note 109190 added to mysqli-stmt.store-result

From: Date: Tue, 26 Jun 2012 19:39:21 +0000
Subject: note 109190 added to mysqli-stmt.store-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-188877@lists.php.net to get a copy of this message
The below note says to use the following order when using store_result; $stmt = $mysqli->prepare("SELECT $column FROM $table") ; $stmt->execute(); $stmt->store_result(); // Fetch a record. Bind the result to a variable called 'value' and fetch. $stmt->bind_result($value) ; $res = $stmt->fetch() ; This seems to be categorically false at least on both servers I use under PHP 5.2. Using store_result and execute before bind_result gave me all sorts of phantom problems with text fields being clipped to one character. Not on every query, but consistently on some queries and only in some scripts. After changing the order to that given in the documentation for execute to $stmt = $mysqli->prepare("SELECT $column FROM $table") ; // Fetch a record. Bind the result to a variable called 'value' and fetch. $stmt->bind_result($value) ; $stmt->execute(); $stmt->store_result(); $res = $stmt->fetch() ; Everything works perfectly. I only spent nine hours attempting a fix for this on a live website for the company I work for searching through memory usage and all sorts of other places trying to track down this phantom bug so I thought this might be useful to someone. Interestingly PHP 5.3 has no problems at all doing it either way when I've tested it. ---- Server IP: 69.147.83.197 Probable Submitter: 98.18.135.250 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.store-result.php Edit -- https://master.php.net/note/edit/109190 Del: integrated -- https://master.php.net/note/delete/109190/integrated Del: useless -- https://master.php.net/note/delete/109190/useless Del: bad code -- https://master.php.net/note/delete/109190/bad+code Del: spam -- https://master.php.net/note/delete/109190/spam Del: non-english -- https://master.php.net/note/delete/109190/non-english Del: in docs -- https://master.php.net/note/delete/109190/in+docs Del: other reasons-- https://master.php.net/note/delete/109190 Reject -- https://master.php.net/note/reject/109190 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188877) next »