note 93707 added to mysqli-stmt.store-result

From: Date: Wed, 23 Sep 2009 19:45:08 +0000
Subject: note 93707 added to mysqli-stmt.store-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-160992@lists.php.net to get a copy of this message
The below statement is only true if you're using ::fetch_row(), which must be called on a result object. Calling $stmt->store_result() effectively converts the statement object to a result object, which you can then call $stmt->fetch_row() on. (I don't know if it's actually converting the object from one type to another in the background, but that's the functional outworking of it.) If you use ::fetch() with a bound result, it is not necessary to call ::store_result. So your two options look like this: <?php //Method 1: bound result if ($stmt = $mysqli->prepare('SELECT name FROM employees')) { $stmt->execute(); $stmt->bind_result($name); while($stmt->fetch()) { echo $name; } } //Method 2: store_result if ($stmt = $mysqli->prepare('SELECT name FROM employees')) { $stmt->execute(); $stmt->store_result(); //"Converts" statement object to result object while($row = $stmt->fetch_row()) { echo $row[0]; } } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 199.74.155.50 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.store-result.php Edit -- https://master.php.net/note/edit/93707 Del: integrated -- https://master.php.net/note/delete/93707/integrated Del: useless -- https://master.php.net/note/delete/93707/useless Del: bad code -- https://master.php.net/note/delete/93707/bad+code Del: spam -- https://master.php.net/note/delete/93707/spam Del: non-english -- https://master.php.net/note/delete/93707/non-english Del: in docs -- https://master.php.net/note/delete/93707/in+docs Del: other reasons-- https://master.php.net/note/delete/93707 Reject -- https://master.php.net/note/reject/93707 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160992) next »