好吧,虐待嘗試解釋它,但請,請道歉我的英語。在MySQL中插入字符串的問題
我有一個腳本將整個數據庫轉儲到一個SQL文件中,然後另一個腳本分割行並執行它們來刪除,創建和插入數據。 問題是某些字符串被「修剪」。它只是插入字符,直到它到達第一個特殊字符,例如:
對於字符串:
"Pantalon azul marino de Poliéster con cinta blanca bordada con el nombre de la institución en uno de sus costados."
它只是插入:
"Pantalon azul marino de Poli"
不引發錯誤。但是,這隻發生在使用腳本,但是當我手動運行查詢並導入phpMyAdmin中的SQL文件一切正常。 順便提一下,一切都設置爲utf8。
我出來的想法,任何幫助將非常感激。
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)'以上 –
@SatishSharma的字段是文本類型:/ –
顯然它必須與包含在字符串中的譯音被截斷。你可以插入字符串,手動從MySQL命令行,而不截斷? –