note 57943 added to function.mysqli-stmt-bind-result
| From: | thejkwhosaysniatgmaildotcom at osu1 dot php dot net | Date: | Wed, 19 Oct 2005 20:12:06 +0000 |
| Subject: | note 57943 added to function.mysqli-stmt-bind-result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97251@lists.php.net to get a copy of this message | ||
I've created these functions which will act like mysqli_fetch_array() and mysqli_fetch_object()
but work with bound results.
<?
function fetch_object() {
$data = mysqli_stmt_result_metadata($this->stmt);
$count = 1; //start the count from 1. First value has to be a reference to stmt.
$fieldnames[0] = &$this->stmt;
$obj = new stdClass;
while ($field = mysqli_fetch_field($data)) {
$fn = $field->name; //get all the feild names
$fieldnames[$count] = &$obj->$fn; //load the fieldnames into an object..
$count++;
}
call_user_func_array(mysqli_stmt_bind_result, $fieldnames);
mysqli_stmt_fetch($this->stmt);
return $obj;
}
function fetch_array() {
$data = mysqli_stmt_result_metadata($this->stmt);
$count = 1; //start the count from 1. First value has to be a reference to the stmt. because
bind_param requires the link to $stmt as the first param.
$fieldnames[0] = &$this->stmt;
while ($field = mysqli_fetch_field($data)) {
$fieldnames[$count] = &$array[$field->name]; //load the fieldnames into an array.
$count++;
}
call_user_func_array(mysqli_stmt_bind_result, $fieldnames);
mysqli_stmt_fetch($this->stmt);
return $array;
}
?>
Hope this helps some people, I was puzzled by this for a while.
----
Manual Page -- http://www.php.net/manual/en/function.mysqli-stmt-bind-result.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57943
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57943&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57943&report=yes
Search -- http://master.php.net/manage/user-notes.php