note 75238 added to function.mysql-unbuffered-query

From: Date: Sat, 19 May 2007 08:30:56 +0000
Subject: note 75238 added to function.mysql-unbuffered-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-126706@lists.php.net to get a copy of this message
to help better understand the usefulness of this function. <?php # For SELECT, SHOW, DESCRIBE or EXPLAIN statements, returns array or dies # For other statements, UPDATE, DELETE, DROP, etc, returns boolean or dies function db_query($sql) { db_connect(); // the results are not yet stored in memory as they would be with mysql_query() if(!$result = mysql_unbuffered_query($sql)) die(mysql_errno()." : ".mysql_error()."\n"); if(is_resource($result)) { $rows = array(); // here we store the results in memory for the first time while($row = mysql_fetch_array($result, MYSQL_BOTH)) $rows[] = $row; } else $rows = $result; return $rows; } ?> so we just cut the amount of memory needed in half to do something like: <?php foreach(db_query("SELECT foo FROM bar") as $value) { // do whatever } ?> kinda nifty, i guess. any better examples? ---- Server IP: 69.147.83.197 Probable Submitter: 74.139.188.96 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-unbuffered-query.php Edit -- https://master.php.net/note/edit/75238 Del: integrated -- https://master.php.net/note/delete/75238/integrated Del: useless -- https://master.php.net/note/delete/75238/useless Del: bad code -- https://master.php.net/note/delete/75238/bad+code Del: spam -- https://master.php.net/note/delete/75238/spam Del: non-english -- https://master.php.net/note/delete/75238/non-english Del: in docs -- https://master.php.net/note/delete/75238/in+docs Del: other reasons-- https://master.php.net/note/delete/75238 Reject -- https://master.php.net/note/reject/75238 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126706) next »