找不到我无法在 MySQL 数据库中存储 ţ、î、ş 等字符的原因。
我的表定义是:
CREATE TABLE IF NOT EXISTS `gen_admin_words_translated` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`word_id` int(10) NOT NULL,
`value` text COLLATE utf8_unicode_ci,
`lang_id` int(2) NOT NULL,
`needUpd` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2689 ;
与数据库的连接是通过以下脚本完成的:
$charset = "UTF8";
$link = mysql_connect($host, $user, $pass);
if(!$link){
die("Unable to connect to database server.");
}
mysql_selectdb($database);
if(function_exists("mysql_set_charset")){
mysql_set_charset($charset, $link);
}else{
mysql_query("SET NAMES $charset");
}
我在页面的头部有:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
脚本是:
$text = 'ţ, î, ş';
mysql_query("insert into gen_admin_words_translated (word_id, lang_id, value, needUpd) values (1, 1, '$text', 1)");
我最终在表中得到的是:
SELECT * FROM `gen_admin_words_translated`
id word_id value lang_id needUpd
5166 1034 ?, 1 1