note 93978 added to mysqli-stmt.bind-result

From: Date: Fri, 09 Oct 2009 19:00:56 +0000
Subject: note 93978 added to mysqli-stmt.bind-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-161601@lists.php.net to get a copy of this message
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). ---- Server IP: 192.41.40.227 Probable Submitter: 80.136.52.231 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-result.php Edit -- https://master.php.net/note/edit/93978 Del: integrated -- https://master.php.net/note/delete/93978/integrated Del: useless -- https://master.php.net/note/delete/93978/useless Del: bad code -- https://master.php.net/note/delete/93978/bad+code Del: spam -- https://master.php.net/note/delete/93978/spam Del: non-english -- https://master.php.net/note/delete/93978/non-english Del: in docs -- https://master.php.net/note/delete/93978/in+docs Del: other reasons-- https://master.php.net/note/delete/93978 Reject -- https://master.php.net/note/reject/93978 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161601) next »