Problems inserting rows in MySQL

Well, I try to explain this, but please apologize for my English.

I have a script that unloads the entire database into an SQL file, and then another script breaks the rows and executes them to delete, create and insert data. The problem is that some lines are "clipped". It simply inserts the string until it reaches 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."

just paste:

 "Pantalon azul marino de Poli"

An error does not occur. But this only happens with a script, but when I run the queries manually and import the SQL file into phpMyAdmin, everything works. By the way, everything is installed on utf8.

I have no ideas, any help would be greatly 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 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 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 "&nbsp;&nbsp; Errno: ".$errno." <br/>";
            echo "&nbsp;&nbsp; Error: ".$error." <br/>";
            $failed++;
        }
        $templine = '';
    }
    }
+3
source share
2 answers

, , , UTF-8.

PHP MySQL - . é , , latin1 , , , > 127. UTF-8. MySQL, UTF-8, , .

:

  • UTF-8
  • , , MySQL

, -:

  • MySQL - . , .
  • - information_schema ALTER TABLE MySQL .
+2

, , . , DB- UTF8:

ALTER TABLE {table_name} CHANGE COLUMN {col_name} {col_name} TEXT CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NOT NULL ;
0

All Articles