我正在尝试将单词表保存到我的数据库中。Wordlist 是一个 utf-8 编码的文本文档。这是我的表结构;
CREATE TABLE IF NOT EXISTS `wordlist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kelime` char(64) COLLATE utf8_turkish_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `kelime` (`kelime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=1140209 ;
这是添加单词的php代码;
<?php
ini_set('max_execution_time', 3000);
$handle = @fopen("wordlist.txt", "r");
if ($handle) {
include("ekle.php"); // makes db connection
$sql = "insert into wordlist (kelime) VALUES (?)";
$dbh->beginTransaction();
$sth = $dbh->prepare($sql);
while (($buffer = fgets($handle, 4096)) !== false) {
$sth->execute(array(trim($buffer)));
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
$dbh->rollBack();
} else {
$dbh->commit();
}
fclose($handle);
}?>
我的数据库的默认排序规则也是 utf-8_turkish_ci。当我添加单词时,我的单词表在 phpmyadmin 上看起来不对;
我在这里做错了什么?