BLenau BLenau - 1 month ago 12
PHP Question

Segmentation Fault from PHP PDO FreeTDS ODBC execution

I am currently migrating a PHP project from using PHP's

library to using the
library with FreeTDS. I have modified all of my database calls, but have run into a very strange problem executing the prepared statements on the SQL Server database.

Below is a snippet of code that I am having the problem with.

public static function gift_cards_exist($start_number, $end_number = null) {
global $sol_donations;
$db = $sol_donations->get_db();

$store_id = get_option('pos-store-id', false);
//$store_id = '01'; // Won't work if value assigned this way
$payment_method = 'Gift';

if (empty($end_number)) {
$end_number = $start_number;

$query = '
SELECT * FROM dbo.tblPmtSerialHdr
AND StoreId = ?';
//AND PmtMethodId = ?';

$stmt = $db->prepare($query);
$stmt->bindParam(1, $start_number, \PDO::PARAM_STR | \PDO::PARAM_INPUT_OUTPUT);
$stmt->bindParam(2, $end_number, \PDO::PARAM_STR | \PDO::PARAM_INPUT_OUTPUT);
$stmt->bindParam(3, $store_id, \PDO::PARAM_STR | \PDO::PARAM_INPUT_OUTPUT);
//$stmt->bindParam(4, $payment_method, \PDO::PARAM_STR | \PDO::PARAM_INPUT_OUTPUT);
$result = $stmt->execute();

$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);

/* Nothing printed from this
echo $stmt->errorCode();
echo '<br />';
echo $stmt->errorInfo();

if ($result) {
return true;
return false;

Here is where the problem exists. Running the code in this form (with all of the commented lines remaining commented) results in correct execution of the query with the expected, although not correct for my program, results.

However, if I modified the query to use the second
statement and uncommented the last
statement to use with the statement, the script will fail causing a segmentation fault. The actual error message that I get in the apache error log is:

[Fri Feb 06 10:43:05.406772 2015] [core:notice] [pid 1415] AH00051: child pid 1541 exit signal Segmentation fault (11), possible coredump in /etc/apache2

I have absolutely no idea why adding this one extra parameter for the prepared statement is causing a problem.

Some extra information about the situation:

FreeTDS is installed correctly and can be used to connect to the database and query the data.

I have tried using both
and both give the same results.

I have tried running the statement with and without the bitwise or with

Finally, I checked to make sure that there are no
in the record set that should be returned to make sure that
values couldn't be the cause.


So, it turns out that this is some sort of bug in the FreeTDS ODBC driver. I switch over to using the dblib driver and all of my queries worked correctly with no segmentation faults.