Re: Using two colomns of mysql data as key/value pairs in arrays
| From: | Peter Beckman | Date: | Mon, 20 Oct 2003 14:23:51 +0000 |
| Subject: | Re: Using two colomns of mysql data as key/value pairs in arrays | ||
| References: | 1 2 3 4 5 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-31169@lists.php.net to get a copy of this message | ||
On Mon, 20 Oct 2003, Jon Kriek wrote:
> Easier is not always "right" or "good script-logic"
>
> Would it be easier for you to type:
>
> mysql_fetch_array($result, MYSQL_ASSOC) {
OK, can we clear this up once and for all?
mysql_fetch_assoc(): 3.7182140350342 seconds [18880 rows]
mysql_fetch_array(): 5.769602060318 seconds [18880 rows]
Same data set in both cases. While there isn't MUCH difference, using
assoc gives one a 30% increase in speed in my rudimentary test over array.
Mysql_fetch_assoc() is faster -- use it. I've learned something.
The code:
$sql = "select * from tblApplications";
list($l,$r) = split(" ",microtime());
$start = $l + $r;
$r = mysql_query($sql);
$num = mysql_num_rows($r);
while( $row = mysql_fetch_assoc($r) ) {
// echo "";
}
list($l, $r) = explode(" ",microtime());
$diff = ((float)$l + (float)$r) - (float)$start;
echo "<hr/>fetch_assoc(): $diff seconds [$num rows]($r.$l : $start)<hr/>";
list($l,$r) = explode(" ",microtime());
$start = ((float)$l + (float)$r);
$r = mysql_query($sql);
$num = mysql_num_rows($r);
while( $row = mysql_fetch_array($r) ) {
// echo "";
}
list($l, $r) = explode(" ",microtime());
$diff = ((float)$l + (float)$r) - (float)$start;
echo "<hr/>fetch_array(): $diff seconds [$num rows]($r.$l : $start)<hr/>";
Beckman
---------------------------------------------------------------------------
Peter Beckman Internet Guy
beckman@purplecow.com http://www.purplecow.com/
---------------------------------------------------------------------------