我正在使用 PHP 来填充公司记录的数据库。我有一个公司名称和他们使用的货币类型的字段。
但是当我使用 PHP 时,如果货币是英语英镑符号 (£),则永远不会插入记录。美元符号 ($) 或任何其他正常字符都没有问题。当我运行 sql 语句并将其直接输入 MySQL 查询浏览器时,带有井号的记录插入得很好。但是当我在 PHP 中运行完全相同的 INSERT 语句时,它就不起作用了。
$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。
谢谢。