PHP PDO 分段错误返回空值
目前,我正在使用 freetds 连接到 MSSql 服务器,在其中提取大量会计数据。数据会很好地拉入,直到达到空值为止。此时我没有收到任何 PHP 错误。相反,我在 apache 错误日志中收到以下错误。
[通知]子进程 pid 10235 退出信号分段错误 (11)
我做了一些搜索,发现 这个页面,但它并没有真正的帮助。我正在使用的查询看起来像这样,
SELECT DISTINCT(t1.PEREND), t2.ERATE, t2.EEXTEND, t2.EARNDED, t1.ENTRYSEQ
FROM UPCHKD as t1 LEFT JOIN
(SELECT EARNDED, PEREND, ERATE, EEXTEND, ENTRYSEQ FROM UPCHKD
WHERE (EARNDED LIKE '401K%'AND EARNDED NOT LIKE '401KL%') AND
EMPLOYEE = ? AND PEREND >= ? AND PEREND <= ?) as t2 ON t1.PEREND = t2.PEREND
WHERE t1.PEREND >= ? AND t1.PEREND <= ? AND t1.EMPLOYEE = ? ORDER BY PEREND
我正在使用如下所示的 while 循环获取数据,
while($result = $sth->fetch(PDO::FETCH_ASSOC)) {
//Deal with data here
}
我无法判断这是否是 PDO、我的数据库层、MSSQL 或我的查询的问题。另外,我想指出,如果我使用 MSSQL studio 手动运行查询,它运行良好,并正确显示空值。
Currently I am using freetds to connect to a MSSql server where I am pulling in a lot of accounting data. The data is pulling in fine until it hits a null value. At that point I am not receiving any PHP errors. Instead I am getting the following error in the apache error log.
[notice] child pid 10235 exit signal Segmentation fault (11)
I did some searching for this and found this page, but it does not really help. The query I am using looks something like this,
SELECT DISTINCT(t1.PEREND), t2.ERATE, t2.EEXTEND, t2.EARNDED, t1.ENTRYSEQ
FROM UPCHKD as t1 LEFT JOIN
(SELECT EARNDED, PEREND, ERATE, EEXTEND, ENTRYSEQ FROM UPCHKD
WHERE (EARNDED LIKE '401K%'AND EARNDED NOT LIKE '401KL%') AND
EMPLOYEE = ? AND PEREND >= ? AND PEREND <= ?) as t2 ON t1.PEREND = t2.PEREND
WHERE t1.PEREND >= ? AND t1.PEREND <= ? AND t1.EMPLOYEE = ? ORDER BY PEREND
And I am getting the data using a while loop like the following,
while($result = $sth->fetch(PDO::FETCH_ASSOC)) {
//Deal with data here
}
I can not tell if this is a problem with PDO, my database layer, MSSQL, or my query. Also, I would like to point out that if I take the query and run it manually using MSSQL studio, it runs fine, and shows the null values properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理分段错误并不有趣。我能给你的最好答案是不断地在不同的地方放置
die('okay');
调用,以查看在遇到段错误之前在不同的编码块中走了多远。 (如果存在段错误,您将看不到任何内容)。尝试将所有内容升级到最新版本也是值得的:PHP、PDO 等。
Segmentation faults are no fun to deal with. The best answer I can give you is to continually place
die('okay');
calls in various places to see how far in different coding blocks you get before you hit a seg fault. (You won't see anything if there was a seg fault).It's also worth just trying to just upgrade everything to the latest versions: PHP, PDO, etc.
解决此问题的一种方法是向所有返回列添加 if null 语句,如下所示,
如果现在找到空值,则将它们返回为零而不会出现错误。它不是最漂亮的,但它很有效。
One solution to this issue works by adding if null statements to all return columns like so,
If nulls are found now, they are returned as zeros without error. It is not the prettiest, but it works.