Well, ill try to explain it but please, apologize my english.
I have a script that dumps an entire database into an SQL file and then another script splits the lines and execute them to drop, create and insert the data. The problem is that some strings are "trimmed". It just insert the string until it reach the first special character, for example:
For the string:
"Pantalon azul marino de Poliéster con cinta blanca bordada con el nombre de la institución en uno de sus costados."
it just insert:
"Pantalon azul marino de Poli"
No error is thrown. But this happens only using the script, but when i run the queries manually and importing the SQL file in phpMyAdmin everything works. Everything is set to utf8 by the way.
I'm out of ideas, any help will be very appreciated.
include ('../core/connection.inc.php');
$conn = dbConnect('admin');
$conn->query("SET NAMES 'utf8'");
$conn->set_charset("utf8");
$type = 0;
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file('db-backup.sql');
// Loop through each line
$correct = 0;
$failed = 0;
foreach ($lines as $line){
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';'){
$templine = str_replace("latin1","utf8",$templine);
$templine = trim($templine);
// Perform the query
$conn->query($templine);
$errno = $conn->errno;
$error = $conn->error;
if($conn->affected_rows > 0){
echo "OK: (".$templine.")<br/>";
$correct++;
} else {
echo "Failed: (".$templine.")<br/>";
echo " Errno: ".$errno." <br/>";
echo " Error: ".$error." <br/>";
$failed++;
}
$templine = '';
}
}
varchar(256)or more