我正在使用PHP来填充公司记录的数据库。我有一个公司名称和他们使用的货币类型的字段。
但是,当我使用PHP的记录永远不会被插入,如果货币是Enlglish英镑符号(£)。美元符号($)或任何其他正常字符是没有问题的。当我运行sql语句并将其直接输入到MySQL查询浏览器中时,带有磅符号的记录插入得很好。但是,当我在PHP中运行完全相同的INSERT语句时,它不起作用。使用PHP无法获取要插入到mysql数据的记录
$sql = "INSERT INTO company_test (name, currency) VALUES ('ABC Widgets', '£')";
$rs = mysql_query($sql, $conn);
//Does not insert a record
$sql = "INSERT INTO company_test (name, currency) VALUES ('ABC Widgets', '$')";
$rs = mysql_query($sql, $conn);
//A record inserts just fine
//My MySQL version is 5.5.11. PHP is version 5.3.6.
//The MySQL table looks like this:
TABLE company_test
FIELD | id | INTEGER(10) | not null | auto increment
FIELD | name | VARCHAR(45) | not null
FIELD | currency | VARCHAR(3)
在MySQL查询浏览器的“表选项”选项卡中显示,该company_test表我的字符集是UTF8。
谢谢。
什么是PHP脚本的字符集? ASCII或UTF8?你有没有从MySQL的任何警告?你有没有试过调用mysql_error()? – 2012-08-09 17:47:34
它可能无助于回答你的问题,但你应该停止使用'mysql_ *'函数。他们正在被弃用。请使用[PDO](http://php.net/manual/en/book.pdo.php)(自PHP 5.1起支持)或[mysqli](http://php.net/manual/en/book)。 mysqli.php)(自PHP 4.1起支持)。如果你不确定使用哪一个,[阅读这篇文章](http://stackoverflow.com/questions/13569/mysqli-or-pdo-what-are-the-pros-and-cons)。 – Matt 2012-08-09 17:48:55
值得可能增加'currency'字段的大小吗?我不知道一个英镑符号会被存储为一个字符还是像'£'这样的字符,这不适合...... – andrewsi 2012-08-09 17:49:51