MySQL Forums
Forum List  »  PHP

Using UTF-8 from PHP
Posted by: Dominique L
Date: May 01, 2015 12:00AM

I am using MySQL from PHP and when I try to insert the following string into an SQL UPDATE query the string is truncated before the last character:

Anastasia or "Staci"🌻

The last character of the string is actually the bytes:

0xf0 0x9f 0x8c 0xbb

which I believe is the UTF-8 representation of that character. The tables in my database look like:

CREATE TABLE `Profiles` (
`GroupId` int(11) NOT NULL,
`MemberId` int(11) NOT NULL,
`Name` varchar(32) NOT NULL,
`Status` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

phpMyAdmin tells me that the fields storing this data are using collation "utf8_general_ci".

I set up each DB connection as follows:

$db = mysql_connect($DbHost, $DbUser, $DbPassword);
if (!$db)
{
WriteError('Could not connect to database in Process: ' . mysql_error());
exit;
}

if (!mysql_select_db($DbName, $db))
{
WriteError("Could not select database $DbName in Process: " . mysql_error());
mysql_close($db);
exit;
}

if (!mysql_query("SET NAMES 'utf8'", $db))
{
WriteError("Could not set UTF-8 in Process: " . mysql_error());
mysql_close($db);
exit;
}

if (!mysql_set_charset('utf8', $db))
{
WriteError("Could not set charset to UTF-8 in Process: " . mysql_error());
mysql_close($db);
exit;
}


The behavior is the same (string truncated) if I do the update via PHP or via the phpMyAdmin Web tool.

Options: ReplyQuote


Subject
Written By
Posted
Using UTF-8 from PHP
May 01, 2015 12:00AM
May 02, 2015 01:19PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.