"what's faster/better to use: the mysql or php md5 function?" Code Answer


if your application is only calcullating md5 when someone registers on your site, or is logging in, own many calls to md5 will you do per hour ? couple of hundreds ? if so, i don't think the really small difference between php and mysql will be significant at all.

the question should be more like "where do i put the fact that password are stored using md5" than "what makes me win almost nothing".

and, as a sidenote, another question could be : where can you afford to spend resources for that kind of calculations ? if you have 10 php servers and one db server already under heavy load, you get your answer ;-)

but, just for fun :

mysql> select benchmark(1000000, md5('test'));
| benchmark(1000000, md5('test')) |
|                               0 |
1 row in set (2.24 sec)

and in php :

$before = microtime(true);
for ($i=0 ; $i<1000000 ; $i++) {
    $a = md5('test');
$after = microtime(true);
echo ($after-$before) . "n";

gives :

$ php ~/developpement/tests/temp/temp.php

but you probably won't be calculating a million md5 like this, will you ?

(and this has nothing to do with preventing sql injections : just escape/quote your data ! always ! or use prepared statements)

By Vickyexpert on May 8 2022

Answers related to “what's faster/better to use: the mysql or php md5 function?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.