note 116827 added to mysqli-stmt.bind-result

From: Date: Thu, 05 Mar 2015 18:31:34 +0000
Subject: note 116827 added to mysqli-stmt.bind-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-201866@lists.php.net to get a copy of this message
For those of you trying to bind rows into array, <?php $stmt = $db->prepare('SELECT id, name, mail, phone, FROM contacts'); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($arr['id'], $arr['name'], $arr['mail'], $arr['phone']); while ($stmt->fetch()) { $outArr[] = $arr; } $stmt->close(); return $outArr; ?> this will give you all the rows you asked for except that they would all be the same as the first one because of some gremlins in the background code (i've heard that PHP is trying to save memory here). But this one works: <?php $stmt = $db->prepare('SELECT id, name, mail, phone, FROM contacts'); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($a,$b,$c,$d); while ($stmt->fetch()) { $outArr[] = ['id' => $a, 'name' => $b, 'mail' => $c, 'phone' => $d]; } $stmt->close(); return $outArr; ?> Just don't use arrays to bind results :) ---- Server IP: 72.52.91.14 Probable Submitter: 88.102.101.178 ---- Manual Page -- http://php.net/manual/en/mysqli-stmt.bind-result.php Edit -- https://master.php.net/note/edit/116827 Del: integrated -- https://master.php.net/note/delete/116827/integrated Del: useless -- https://master.php.net/note/delete/116827/useless Del: bad code -- https://master.php.net/note/delete/116827/bad+code Del: spam -- https://master.php.net/note/delete/116827/spam Del: non-english -- https://master.php.net/note/delete/116827/non-english Del: in docs -- https://master.php.net/note/delete/116827/in+docs Del: other reasons-- https://master.php.net/note/delete/116827 Reject -- https://master.php.net/note/reject/116827 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201866) next »