Voting

: nine minus eight?
(Example: nine)

The Note You're Voting On

tuxedobob
9 years ago
If you're used to working with sqlsrv_query, you're probably used to the following flow:

<?php
$query
= "SELECT * FROM mytable WHERE id=?";
$result = sqlsrv_query($conn, $query, array($myID));
$row = sqlsrv_fetch_array($result);
?>

Given that, you might think the following works:

<?php
$myID
= 0;
$query = "SELECT * FROM mytable WHERE id=?";
$stmt = sqlsrv_prepare($conn, $query, array(&$myID));
$result = sqlsrv_execute($stmt);
$row = sqlsrv_fetch_array($result);
?>

It doesn't. The reason is that sqlsrv_execute, as noted above, returns true or false on success or failure, respectively. The variable that has your result is actually $stmt. Change the last row to

<?php
$row
= sqlsrv_fetch_array($stmt);
?>

and it works as expected.

<< Back to user notes page

To Top