Comparing row equivalence between mysql database and php code

I wonder if it is possible to compare two strings using MySQL and PHP and get the same results. In MySQL, I have:

a = b collate utf8_general_ci

For PHP, I found a promising way to do this with the Transliterator class

transliterator_transliterate($a, 'NFD; [:Nonspacing Mark:] Remove; NFC; Lower();') = transliterator_transliterate($b, 'NFD; [:Nonspacing Mark:] Remove; NFC; Lower();')

Both will do the same most of the time, but it seems like there is no way to compare two strings in PHP, both without accent and case insensitive, which are compatible with MySQL.

Does anyone have a better solution to get the same result in PHP and MySQL, or is this something that should be avoided anyway by moving the whole comparison to either the database or the application code?

Context is replication between MySQL and a proprietary database. I have a unique key in a database in a text box in MySQL. On the other hand, I have thousands of rows in memory, and I would like to filter unique values ​​in PHP without trying to insert them into the MySQL table first. My approach is to use these values ​​as keys in an array to keep them unique. Now the problem is to normalize these keys in such a way as to process the same values ​​as the unique index in MySQL.

+4
source share
1 answer

Even if you achieve this and validate some tests, it may not be reliable due to the different internal implementation of php and mysql string comparisons.

, , . , , , , .

-, php , mysql. mysql . , . , .

+1

All Articles