note 118934 added to function.sqlsrv-execute

From: Date: Tue, 01 Mar 2016 16:53:21 +0000
Subject: note 118934 added to function.sqlsrv-execute
Groups: php.notes 
Request: Send a blank email to php-notes+get-205079@lists.php.net to get a copy of this message
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. ---- Server IP: 72.52.91.14 Probable Submitter: 96.233.109.34 ---- Manual Page -- http://php.net/manual/en/function.sqlsrv-execute.php Edit -- https://master.php.net/note/edit/118934 Del: integrated -- https://master.php.net/note/delete/118934/integrated Del: useless -- https://master.php.net/note/delete/118934/useless Del: bad code -- https://master.php.net/note/delete/118934/bad+code Del: spam -- https://master.php.net/note/delete/118934/spam Del: non-english -- https://master.php.net/note/delete/118934/non-english Del: in docs -- https://master.php.net/note/delete/118934/in+docs Del: other reasons-- https://master.php.net/note/delete/118934 Reject -- https://master.php.net/note/reject/118934 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205079) next »