Question

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.

Was it helpful?

Solution 2

One solution to this issue works by adding if null statements to all return columns like so,

ISNULL(t2.ERATE, 0) as ERATE, ISNULL(t2.EEXTEND, 0) as EEXTEND, ISNULL(t2.EARNDED, '') as EARNDED

If nulls are found now, they are returned as zeros without error. It is not the prettiest, but it works.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top