Question

Okay this is weird to me, but I'm hoping this is an issue that's happened and I have just not found the solution online yet.

Help is very much appreciated.

I am doing a call to a stored procedure on a MS 2008 SQL server. Using SQL Server Management studio, we can verify that this procedure is working correctly.

I wrote a basic script which grabs each row and does a print_r of it.

Now for the weird part. For any row that has a NULL entry (even just one column), PHP simply does not get it, the row is left out, for all others they come in just fine. So if I go back in and manually change the NULL entries and just put text there, they show up.

So basically, this one column that I have which is allowed to be NULL, when it is NULL nothing comes up data wise for that row (it's left out) in PHP. But if you then go in and manually add something it shows up no problem.

According to phpinfo the connector I am using is Free TDS.

Was it helpful?

Solution

This what fixed it for me:

set ANSI_NULL_DFLT_ON ON

I had to query this first before calling any stored procedures

$result = mssql_query('set ANSI_NULL_DFLT_ON ON');

Hope that helps for anyone who had my problem. It was really frustrating, apparently you need this so PHP will return rows that have null columns in it and it has something to do with a compare inside the stored procedure. I believe it's when comparing something that might have a NULL value, PHP will ignore the entire row unless you pass this first.

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