Question

I am just wondering whether it would be better to use PHP's Soundex Function or MySQL's Soundex Function?

Also do the PHP and MySQL Soundex function produce the same results?

Was it helpful?

Solution

This is an ancient debate in web application design. It all depends. Some people like to store business logic only in the PHP code and just use databases for storage. Others say the overhead required for PHP isn't worth it on massive CRUD operations. It really comes down to preference.

OTHER TIPS

I tend to pass as much calculations to SQL engine as native functions in SQL are faster then getting a dataset and producing the same result in PHP. This is valid especially for native functions and maybe is not a good idea to transfer your business logic to it as it will become more difficult to manage, debug or extend.

Re:Also do the PHP and MySQL Soundex function produce the same results?

No they don't MySQL soundex is looser therefor i recommend using php, for ex:

<?php
echo soundex('pilchick')."\n";
echo soundex('polack')."\n";
?>

Returns

P422
P420

So when you search for where soundex(Lname) = Soundex('pilchick') you don't get pollack which is good, vs MySQL

Select Soundex('pilchick'), Soundex('polack') From table

result =

------------------------------------------
|Soundex('pilchick') | Soundex('polack')
----------------------------------------
|P420                | P420
----------------------------------------

They both return the same value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top