note 102179 added to mysqli-stmt.bind-result

From: Date: Tue, 01 Feb 2011 09:02:02 +0000
Subject: note 102179 added to mysqli-stmt.bind-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-176551@lists.php.net to get a copy of this message
I wrote a function that fetches all rows from a result set - either normal or prepared. <?php function fetch($result) { $array = array(); if($result instanceof mysqli_stmt) { $result->store_result(); $variables = array(); $data = array(); $meta = $result->result_metadata(); while($field = $meta->fetch_field()) $variables[] = &$data[$field->name]; // pass by reference call_user_func_array(array($result, 'bind_result'), $variables); $i=0; while($result->fetch()) { $array[$i] = array(); foreach($data as $k=>$v) $array[$i][$k] = $v; $i++; // don't know why, but when I tried $array[] = $data, I got the same one result in all rows } } elseif($result instanceof mysqli_result) { while($row = $result->fetch_assoc()) $array[] = $row; } return $array; } ?> Simply call it passing a result set or executed statement and you'll get all rows fetched. ---- Server IP: 69.147.83.197 Probable Submitter: 46.134.223.226 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-result.php Edit -- https://master.php.net/note/edit/102179 Del: integrated -- https://master.php.net/note/delete/102179/integrated Del: useless -- https://master.php.net/note/delete/102179/useless Del: bad code -- https://master.php.net/note/delete/102179/bad+code Del: spam -- https://master.php.net/note/delete/102179/spam Del: non-english -- https://master.php.net/note/delete/102179/non-english Del: in docs -- https://master.php.net/note/delete/102179/in+docs Del: other reasons-- https://master.php.net/note/delete/102179 Reject -- https://master.php.net/note/reject/102179 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176551) next »