note 82742 added to mysqli-stmt.fetch

From: Date: Thu, 24 Apr 2008 00:38:21 +0000
Subject: note 82742 added to mysqli-stmt.fetch
Groups: php.notes 
Request: Send a blank email to php-notes+get-138722@lists.php.net to get a copy of this message
This function uses the same idea as the last, but instead binds the fields to a given array. <?php function stmt_bind_assoc (&$stmt, &$out) { $data = mysqli_stmt_result_metadata($stmt); $fields = array(); $out = array(); $fields[0] = $stmt; $count = 1; while($field = mysqli_fetch_field($data)) { $fields[$count] = &$out[$field->name]; $count++; } call_user_func_array(mysqli_stmt_bind_result, $fields); } // example $stmt = $mysqli->prepare("SELECT name, userid FROM somewhere"); $stmt->execute(); $row = array(); stmt_bind_assoc($stmt, $row); // loop through all result rows while ($stmt->fetch()) { print_r($row); } ?> ---- Server IP: 216.235.15.211 Probable Submitter: 142.161.209.58 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.fetch.php Edit -- https://master.php.net/note/edit/82742 Del: integrated -- https://master.php.net/note/delete/82742/integrated Del: useless -- https://master.php.net/note/delete/82742/useless Del: bad code -- https://master.php.net/note/delete/82742/bad+code Del: spam -- https://master.php.net/note/delete/82742/spam Del: non-english -- https://master.php.net/note/delete/82742/non-english Del: in docs -- https://master.php.net/note/delete/82742/in+docs Del: other reasons-- https://master.php.net/note/delete/82742 Reject -- https://master.php.net/note/reject/82742 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138722) next »