microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.8k stars 374 forks source link

sqlsrv_query with $params containing a NULL redefines NULL in php #2

Closed v-mabarw closed 10 years ago

v-mabarw commented 10 years ago

When a NULL value exists in the parameters when calling sqlsrv_query, it replaces the PHP NULL value with a reference. All variables end up containing the same value.

E.g.
$params = array('abd' 'def', NULL);
sqlsrv_query($conn, $tsql, $params);

NULL is now a reference, so:
$newVar = '123'; // ALL null values now become '123'
$otherVar = '456' // $newVar, $otherVar and $params[2] are all '456', along with any other variables that happen to be NULL.

I posted this in the MSDN forum: http://social.msdn.microsoft.com/Forums/en- US/sqldriverforphp/thread/b4f0fdc1-62ce-4449-95f1-a9536311223a

Sorry, I'm not great at describing things.

Work Item Details

Original CodePlex Issue: Issue 12205 Status: Closed Reason Closed: Unassigned Assigned to: Unassigned Reported on: Dec 24, 2008 at 9:28 AM Reported by: robertjohnson Updated on: May 29, 2009 at 8:45 PM Updated by: icosahedron Closed on: May 29, 2009 at 8:45 PM

v-mabarw commented 10 years ago

On 2009-05-30 03:44:49 UTC, icosahedron commented:

The workaround is to add a & to each parameter. This is now documented in CU2. When a variable without an & is passed as a parameter, a warning is issued as well.