note 81350 modified in function.mysqli-stmt.bind-result by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 22:34:34 +0000 |
| Subject: | note 81350 modified in function.mysqli-stmt.bind-result by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147359@lists.php.net to get a copy of this message | ||
Although inspired by an earlier post, this method could be added to any of your database objects.
It's an object oriented implementation of an earlier post.
The method returns an array with objects representing a row. Each property represents a column and
its value.
<?php
private function getresult($stmt)
{
$result = array();
$metadata = $stmt->result_metadata();
$fields = $metadata->fetch_fields();
for (;;)
{
$pointers = array();
$row = new stdClass();
$pointers[] = $stmt;
foreach ($fields as $field)
{
$fieldname = $field->name;
$pointers[] = &$row->$fieldname;
}
call_user_func_array(mysqli_stmt_bind_result, $pointers);
if (!$stmt->fetch())
break;
$result[] = $row;
}
$metadata->free();
return $result;
}
?>
--was--
Although inspired by an earlier post, this method could be added to any of your database objects.
It's an object oriented implementation of an earlier post.
The method returns an array with objects representing a row. Each property represents a column and
its value.
<?php
private function getresult($stmt)
{
$result = array();
$metadata = $stmt->result_metadata();
$fields = $metadata->fetch_fields();
for (;;)
{
$pointers = array();
$row = new stdClass();
$pointers[] = $stmt;
foreach ($fields as $field)
{
$fieldname = $field->name;
$pointers[] = &$row->$fieldname;
}
call_user_func_array(mysqli_stmt_bind_result, $pointers);
if (!$stmt->fetch())
break;
$result[] = $row;
}
$metadata->free();
return $result;
}
?>
http://php.net/manual/en/function.mysqli-stmt.bind-result.php