note 116728 added to mysqli-stmt.bind-result
| From: | Masterkitano | Date: | Fri, 20 Feb 2015 03:53:21 +0000 |
| Subject: | note 116728 added to mysqli-stmt.bind-result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201763@lists.php.net to get a copy of this message | ||
for people who doesn't have the mysqlInd driver or for some reason just can't use the
stmt->get_result, I've made this function which allows you to "mimic" the
mysqli_result::fetch_assoc:
function fetchAssocStatement($stmt)
{
if($stmt->num_rows>0)
{
$result = array();
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params[] = &$result[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
$stmt->fetch();
return $result;
}
return null;
}
you can use it in a while sentence to fetch and return an assoc array from the statement (as long as
the statement is open):
usage:
$statement = $mysqli->prepare($query));
$statement.execute();
while($rowAssocArray = fetchAssocStatement($statement))
{
//do something
}
$statement.close();
hope this helps.
----
Server IP: 72.52.91.14
Probable Submitter: 189.212.185.85
----
Manual Page -- http://php.net/manual/en/mysqli-stmt.bind-result.php
Edit -- https://master.php.net/note/edit/116728
Del: integrated -- https://master.php.net/note/delete/116728/integrated
Del: useless -- https://master.php.net/note/delete/116728/useless
Del: bad code -- https://master.php.net/note/delete/116728/bad+code
Del: spam -- https://master.php.net/note/delete/116728/spam
Del: non-english -- https://master.php.net/note/delete/116728/non-english
Del: in docs -- https://master.php.net/note/delete/116728/in+docs
Del: other reasons-- https://master.php.net/note/delete/116728
Reject -- https://master.php.net/note/reject/116728
Search -- https://master.php.net/manage/user-notes.php