我编写了一个 PHP 脚本来使用 Unicode 数据填充 MySQL 表。不过,我遇到了一些小问题。例如,空格character
字符 (id = 32) 的列是空的,即使我单独运行以下命令:
UPDATE unicode SET `character` = ' ' WHERE id = 32;
有任何想法吗?这是我用来填充表的脚本(包含的脚本common.php
定义了database
函数,它是一个 PDO 对象):
<?php
include_once('common.php');
// Fetch data from Unicode website
$file = fopen('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt', 'r');
// Iterate through each line of the file
while($row = fgets($file)) {
// Gather data
$column = explode(';', $row);
$id = hexdec($column[0]);
$name = $column[1];
$general_category = $column[2];
$uppercase_mapping = hexdec($column[12]);
$lowercase_mapping = hexdec($column[13]);
$titlecase_mapping = hexdec($column[14]);
// Build the database query
$query = sprintf("INSERT IGNORE INTO unicode VALUES (%d, CHAR(%d USING UTF8), '%s', '%s', %d, %d, %d)",
$id,
$id,
$name,
$general_category,
$uppercase_mapping,
$lowercase_mapping,
$titlecase_mapping);
database()->query($query);
echo $id.' ';
}
?>