开发者

Is it better to use PHP or MySQL for Soundex queries?

开发者 https://www.devze.com 2023-02-21 01:34 出处:网络
I am just wondering whether it would be better to use PHP\'s Soundex Function or MySQL\'s Soundex F开发者_StackOverflowunction?

I am just wondering whether it would be better to use PHP's Soundex Function or MySQL's Soundex F开发者_StackOverflowunction?

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消