RE: [PHP] Re: Formating datevariables...
| From: | John Holmes | Date: | Wed, 24 Jul 2002 03:10:24 +0000 |
| Subject: | RE: [PHP] Re: Formating datevariables... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109201@lists.php.net to get a copy of this message | ||
> Sure using MySQL specific calls is faster but makes you more dependant
> on MySQL and thus makes your application less portable to other
databases.
>
> 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];
}
return;
}
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));
}
return;
}
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
times.
Results:
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
Bergmann.
---John Holmes...