News:

Support the VirtueMart project and become a member

Main Menu

Virtuemart should change to utf8mb4_general_ci !

Started by Studio 42, August 23, 2018, 18:16:52 PM

Previous topic - Next topic

Studio 42

Hi,
I had a problem last days about translating Products that returned a Joomla error 1267(mysql collation error).
I tried all, added a UTF8 function to check it's right encoded and read this post http://forum.virtuemart.net/index.php?topic=140799.msg495424#msg495424
EvanGR had the answer and i was thinking it's stupid, we use already UTF8, so it cannot fails !
But mysql use not a full UTF8 collation it crop a part of the charcode see
https://medium.com/@adamhooper/in-mysql-never-use-utf8-use-utf8mb4-11761243e434
QuoteThe "utf8" encoding only supports three bytes per character. The real UTF-8 encoding — which everybody uses, including you — needs up to four bytes per character.

So as last ressort, i changed collation in table using
ALTER TABLE `XXX_virtuemart_products_fr_fr` CHANGE `product_s_desc` `product_s_desc` VARCHAR(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', CHANGE `product_desc` `product_desc` MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, CHANGE `product_name` `product_name` VARCHAR(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', CHANGE `metadesc` `metadesc` VARCHAR(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', CHANGE `metakey` `metakey` VARCHAR(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', CHANGE `customtitle` `customtitle` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', CHANGE `slug` `slug` VARCHAR(192) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '';

And now all is working, no more collation error, no Joomla error 1267 !
If you search a little, you see other post about this, this is a know problem, it's why mysql team aded utf8mb4 so you can solve now the problem, but old table that dont need to be converted can coontinue to work.

Studio 42

I had another problem about RTL language.
Using strlen($value) do not give right length
You have to use mb_strlen($value,'UTF-8') and to crop text mb_substr($value,0,160);