Re: Using two colomns of mysql data as key/value pairs in arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/
---------------------------------------------------------------------------

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux