Reputation: 9
I am receiving Segmentation Fault(core dumped)
error in odbc_fetch_array
. Though I am having 1500 results by executing (odbc_exec
) a MSSQL query in a $resultSet
variable which initiated globally, I am trying to fetch each row and store it to an array using odbc_fetch_array
in while
loop. When I tried to run the script, from 1500 rows first 7 rows have been fetched and stored in the array. But after that the Segmentation Fault(core dumped)
error arise and stopped the fetching process.
Here is the code I am using:
$i=1;
$display_data = array();
while($data = odbc_fetch_array($this->ressultSet))
{
$display_data[$i] = $data ;
$i++;
}
Can anyone help in this issue?
Thank You!
Upvotes: 0
Views: 1796
Reputation: 43
you can find this error at https://bugs.php.net/bug.php?id=61387&edit=1.
I have isolated the problem to odbc_fetch_array() for result sets that contain an anonymous (unnamed) column with a NULL value. If NULL value is aliased ("SELECT NULL as SOMETHING") there is no crash. If an anonymous (unnamed) column contains anything other than NULL, there is no crash.
Test Script:
$sql = 'SELECT NULL';
$c = odbc_connect('Driver=SQL Server Native Client
11.0;server=hpesc1;uid=xxx;pwd=xxx;Database=xxx','','');
$e = odbc_exec($c, $sql);
$row = odbc_fetch_array($e);
Here are different combinations of SQL that will or won't crash PHP:
$sql = 'SELECT NULL'; // PHP SEGFAULT
$sql = 'SELECT NULL as [one]'; // OK
$sql = 'SELECT 1'; // OK
$sql = 'SELECT 1, NULL'; // SEGFAULT
$sql = 'SELECT 1, NULL as [two]'; // OK
I resolved making something like this in my query:
SELECT * FROM foo ORDER BY id ASC
Hope it helps,
Marco.
Upvotes: 1