0

My Schema is set for Latin1 default collation.

my PHP code:

$result = $conn->sql('CALL _TESTE("á é ô ã ç")');

my _TESTE procedure

CREATE DEFINER=`root`@`%` PROCEDURE `_TESTE`(IN vTarNom VARCHAR(255))
BEGIN
    INSERT INTO _TEMP VALUES (NULL, vTarNom);
END

What is beeing inserted:

á é ô ã ç

I want to save exactly what I sent: á é ô ã ç

Any help?

Edited: If I call the procedure from workbench sending "á é ô ã ç", it inserts correctly, just when called by PHP that converts.

Fabio Colombini
  • 112
  • 1
  • 12
  • 1
    I would highly suggest switching to [utf8mb4](https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html) for your collation. It will definitely support your characters – Machavity Apr 19 '16 at 17:33
  • `SHOW CREATE PROCEDURE _TESTE \G` -- you may find that the procedure is using latin1. – Rick James Apr 22 '16 at 02:42
  • The procedure is latin1. I think the problem is not with the procedure, table or schema, because if I call the procedure inside workbench, it inserts the latin1 characters correctly. – Fabio Colombini Apr 26 '16 at 14:25

1 Answers1

1

You're inserting UTF-8 into a Latin1 database. The quick fix here is to convert your UTF-8 string to Latin1 but the best plan is to make your database UTF-8.

Latin1 might be fine for most languages but it can't handle other symbols that are frequently used by people.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • 1
    Related http://stackoverflow.com/questions/2708958/differences-between-utf8-and-latin1 – Machavity Apr 19 '16 at 17:31
  • @tadman, I´m sending latin1 characters 'á é ô ã ç' from PHP, but somehow, it is arriving UTF8 in the procedure. If I call the procedure direct from workbench (for example), passing 'á é ô ã ç', it inserts perfectly. – Fabio Colombini Apr 19 '16 at 17:37
  • 1
    you have to maintain the same charset through the ENTIRE process. code->db connection->table->field. if any of the stages have a different charset, you WILL corrupt the text - either use the same charset throughout, or have appropriate charset translation logic at the "borders". – Marc B Apr 19 '16 at 17:39
  • @MarcB It's actually worse than that as you need to ensure that *client* -> PHP -> connection -> table -> field is all UTF-8. Sometimes the client is sending the wrong encoding and PHP doesn't care, passing it on as if it's correct. – tadman Apr 19 '16 at 17:42
  • But in my example, I´m sending latin1 'á é ô ã ç' by PHP. Then the Schema is latin1, the table is latin1. I don´t know why it´s inserting in UTF8. Just when the procedure is called by PHP. – Fabio Colombini Apr 19 '16 at 17:48
  • @FabioColombini Like Marc said, you need to check every link in the chain. What's your connection set to? – tadman Apr 19 '16 at 17:49