php - Problems inserting strings in MySQL -


well, ill try explain please, apologize english.

i have script dumps entire database sql file , script splits lines , execute them drop, create , insert data. problem strings "trimmed". insert string until reach first special character, example:

for string:

"pantalon azul marino de poliéster con cinta blanca bordada con el nombre de la institución en uno de sus costados." 

it insert:

 "pantalon azul marino de poli" 

no error thrown. happens using script, when run queries manually , importing sql file in phpmyadmin works. set utf8 way.

i'm out of ideas, appreciated.

    include ('../core/connection.inc.php');     $conn = dbconnect('admin');     $conn->query("set names 'utf8'");     $conn->set_charset("utf8");     $type = 0;      // temporary variable, used store current query     $templine = '';     // read in entire file     $lines = file('db-backup.sql');     // loop through each line     $correct = 0;     $failed = 0;     foreach ($lines $line){     // skip if it's comment     if (substr($line, 0, 2) == '--' || $line == '')         continue;     // add line current segment     $templine .= $line;     // if has semicolon @ end, it's end of query     if (substr(trim($line), -1, 1) == ';'){         $templine = str_replace("latin1","utf8",$templine);         $templine = trim($templine);          // perform 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 "&nbsp;&nbsp; errno: ".$errno." <br/>";             echo "&nbsp;&nbsp; error: ".$error." <br/>";             $failed++;         }         $templine = '';     }     } 

i'm guessing dump file you're importing isn't utf-8.

php piping bytes file mysql without conversion. é character in file in latin1 based on change you're making, represented single byte value > 127. isn't utf-8. you've promised mysql you'll send valid utf-8, , stops reading string when gets invalid byte.

you might consider:

  • re-encoding dump file utf-8
  • figuring out encoding dump file in, , loading mysql using encoding

personally think i'd approach problem different way:

  1. load dump file mysql using command-line client, or similar. know works.
  2. alter character set of each column after importing - can use data in information_schema assemble alter table statements , mysql conversion properly.

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -