> Sure using MySQL specific calls is faster but makes you more dependant
> on MySQL and thus makes your application less portable to other
> Cameron

Of course. It depends on your application. I know I'm only going to use
MySQL for the programs I'm doing now, so I can use this _faster_ method.

I felt weird about saying it was faster before, so I did some
benchmarking to make sure I could back up what I was saying. Using these
two functions:

function sql_method()
    $query = "SELECT DATE_FORMAT(date_column,'%d%m%Y') FROM benchmark";
    $result = mysql_query($query);
    while($row = mysql_fetch_row($result))
        $field = $row[0];


function php_method()
    $query = "SELECT date_column+0 FROM benchmark";
    $result = mysql_query($query);
    while($row = mysql_fetch_row($result))
        $dag = substr ( $row[0], 6, 2 );
        $mnd = substr ( $row[0], 4, 2 );
        $aar = substr ( $row[0], 0, 4 );

        $field = date ("dmY", mktime(0,0,0,$mnd,$dag,$aar));


There were 1000 rows in the one column table, the single column being a
random date in the standard MySQL format. Each function was run 10


SQL/PHP Date Manipulation       total time      average iteration time  
100% SQL Method                         18ms            0.0175564  
279% PHP Method                 49ms            0.0489336  

Your results may vary. I used some benchmark class by Sebastian

---John Holmes...

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

Reply via email to