note 93978 deleted from mysqli-stmt.bind-result by danbrown
| From: | danbrown@php.net | Date: | Fri, 09 Oct 2009 19:36:32 +0000 |
| Subject: | note 93978 deleted from mysqli-stmt.bind-result by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161602@lists.php.net to get a copy of this message | ||
Note Submitter: Marc Gutt
----
As there are several versions to obtain a data set, I've made some benchmarks:
http://www.programmierer-forum.de/topic-t116918.htm
As you can see, there are two possible ways.
Version 1:
<?php
// 1. run 0.14501937151
// 2. run 0.145541801453
// 3. run 0.141622686386
// fastest run 0.0934751033783
$id = 1111;
if ($stmt = $db->prepare(
"SELECT *
FROM emails
WHERE id = ?
LIMIT 100"
)) {
$stmt->bind_param('i', $id);
$stmt->execute();
$meta = $stmt->result_metadata();
while ($field = $meta->fetch_field()) {
$row[] = &$fields[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $fields);
unset($meta, $row);
$i = 0;
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$data[$i][$k] = $v;
}
$i++;
}
unset($stmt);
}
?>
Version 7:
<?php
// 1. run 0.145406525135
// 2. run 0.147244937418
// 3. run 0.146580169201
// 4. run 0.140648040772 (rtrim removed)
// 5. run 0.138385720253 ($i used as string and counter)
// 6. run 0.142242712975
// fastest run 0.0888710021973
$id = 1111;
if ($stmt = $db->prepare(
"SELECT *
FROM emails
WHERE id = ?
LIMIT 100"
)) {
$stmt->bind_param('i', $id);
$stmt->execute();
$meta = $stmt->result_metadata();
$i = '';
while ($field = $meta->fetch_field()) {
$i .= ($i ? ',' : '$stmt->bind_result(') . '$fields["' .
$field->name . '"]';
}
unset($meta);
eval($i . ');');
$i = 0;
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$data[$i][$k] = $v;
}
$i++;
}
unset($stmt);
}
?>
Don't forget to close() or unset() $match and $stmt!
The on-the-fly copy function is the slowest (defining $copy outside of the benchmark loop
doesn't help, too).