I am stuck with a piece of PHP code (PHP 5) where I am running an SQL query (Transact SQL).
The Code (which is not working):
$query = "
UPDATE my_table
SET my_column = 'some_value'
WHERE my_id IN (?);" // does not work :-(
sqlsrv_query($my_connection, $query, array('abc', 'def', 'ghi')); // does not work :-(
What I am trying to do: Update my_table in my_column for rows with my_id equal to abc, def and ghi.
However, when I write the same SQL query with no parameters (this works):
$query = "
UPDATE my_table
SET my_column = 'some_value'
WHERE my_id IN ('abc', 'def', 'ghi');" // works :-)
sqlsrv_query($my_connection, $query); // works :-)
I've tried to execute the sqlsrv_query command like this
sqlsrv_query($my_connection, $query, array('abc', 'def', 'ghi'));
and like this
sqlsrv_query($my_connection, $query, array(array('abc', 'def', 'ghi')));
and like this
sqlsrv_query($my_connection, $query, 'abc', 'def', 'ghi');
None of them work.
Can someone please help me? I've had a good read on the manual. And writing the SQL like this
... WHERE my_id IN (?,?,?)...
is not an option since my array will contain a variable amount of values!
Thank you!
$query = "UPDATE ... WHERE my_id IN (" . implode(',', array_fill(0, count($ids), '?')) . ")";Easily handles multiple bound parameters. Be weary of the maximum limit.