Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MD5 Vs MySQL md5

Tags:

php

mysql

md5

This is something I have been wondering about. Is it faster to have MySQL handle my md5 hashing or should I let PHP handle it?

like image 438
WojonsTech Avatar asked May 02 '26 14:05

WojonsTech


2 Answers

Actually I think the MySQL MD5 implementation will be faster.

PHP's native md5() has a bit of a messy implementation of the algorithm. When hashing MD5 with PHP5 I would recommend to use hash('md5',$var); which is proved to be faster.

Make your own benchmarks though.

See this page (Comment at the bottom).

0.33311605453491: hash/md5
1.0671429634094: md5
like image 75
thwd Avatar answered May 05 '26 04:05

thwd


just comparing the performance, there won't be any noticeable difference (i think the mysql-implementation will be a very very [...] tiny little bit faster).

try to use the solution that results in more redable (and that way easier maintainable) code. for me, this is doing things like hashing in php, but i don't know what your code looks like, so maybe letting mysql do the job is easier for you.

PS: if you're using this for passwords, think about using another algorithm for hashing (sha256 for example). for more information, take a look at wikipedia and read about collisions.

like image 28
oezi Avatar answered May 05 '26 04:05

oezi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!