1

This is on my windows test platform.

I have the following csv:

You have signed out successfully!,ar,لقد خرجت بنجاح!

I have the following table definition:

CREATE TABLE `translations` (
  `sourcephrase` varchar(250) NOT NULL,
  `language` char(5) NOT NULL,
  `translatedphrase` varchar(250) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`sourcephrase`,`language`),
  KEY `language` (`language`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

If I load this csv into table (via mysql workbench, import csv), I get the data just fine.

sourcephrase, language, translation
You have signed out successfully!   ar  لقد خرجت بنجاح!

If instead I run this php code (where psquery is just execute a prepared statement):

    $sourcephrase="You have signed out successfully!";
    $language="ar";
    $translated="لقد خرجت بنجاح!";
    $sql = "insert into translations (sourcephrase, language, translatedphrase) values (?,?,?)";
    $this->DB->psquery($sql, array("sss", $sp, $language, $translated));

The table contains the following data:

You have signed out successfully!   ar  لقد خرجت بنجاح!

Why am I getting a different result in php ? (I know its something utf8 related, but I can't see what). I don't believe it's mysql related, as the csv import is just fine.

David Shields
  • 596
  • 1
  • 12
  • 34

1 Answers1

1

لقد خرجت بنجاح! is Mojibake for the desired string. See this for the likely causes, best practice, and debugging techniques.

Probably this item is relevant to your PHP connection: "The connection when INSERTing and SELECTing text needs to specify utf8 or utf8mb4."

Community
  • 1
  • 1
Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Wow, that link is pure gold.I wish I could upvote multiple times. Mr James, you are the business for utf-8. I can't decide whether to bookmark your answer or your name! – David Shields May 16 '17 at 07:55
  • @DavidShields - Hehe. Thanks. I have struggled for years to consolidate scattered advice into that single location. (You could upvote the question _and_ the answer.) – Rick James May 16 '17 at 15:14
  • Done, and done. Because, well, why wouldn't you ? Well deserved upvotes. – David Shields May 18 '17 at 09:49