phpsql-serverpdo

Inconsistent Nameless Column Handling Across Servers


I'm running a very simple query across two different servers, on two different PHP versions, and getting inconsistent results. I can change my query to get consistent results, so I've figured out what went wrong, but I'd like some pointers on why this happened.

My query is a very simple SELECT COUNT(*) FROM '{$table}', then fetching the associative array with PDO. Works fine when there's a result. When there are no results found, however, the results are inconsistent.

On one server (PHP 7.4.24), I get the following result from print_r:

Array
{
    [0] => (int) 0
}

However, on the other server (PHP 7.4.6), I get the following result from the same query:

Array
{
    [computed] => (string) 0
}

They are not pulling from the same SQL Server, but one table is a copy of the other, so while a table difference wouldn't explain this, a database setting might. Exact same code, so there must be something weird on either the PHP version or some server configs.

Any idea what setting/extension/whatever could cause a difference like this?


Solution

  • Circling back to this. Sure, it's years later, but this may help someone.

    This was caused by inconsistent SQL drivers. Because of a minor OS difference, I had to use different drivers, and they had inconsistent behavior on calculated, unnamed columns. Updating the driver fixed it.