Why do a string truncate when a try to insert in a MySQL table? The string truncates before the character á
. For instance, Málaga - Real Madrid
becomes only a M
in the database.
//***
login & select databas开发者_如何学运维e
//***
$mysqli->query('set names utf8');
$title = $mysqli->real_escape_string('Málaga - Real Madrid');
$mysqli->query("INSERT INTO article (title) VALUES ('$title')");
You can use PHP to split a string at your character á
<?php
// Put the data in to a string
$string = 'Málaga - Real Madrid';
// Split it by the character
$split_string = explode('á', $string);
//***
login & select database
***/
$mysqli->query('set names utf8');
// Put the first split in to the real_escape function
$title = $mysqli->real_escape_string($split_string[0]);
// Run the query
$mysqli->query("INSERT INTO article (title) VALUES ('$title')");
?>
精彩评论