I am using PHP to populate a database of company records. I have a field for company name and the currency type that they use.
But when I use PHP the record never gets inserted if the currency is an Enlglish pound sign (£). A dollar sign ($) or any other normal character is no problem. The record with a pound sign inserts just fine when I run the sql statement and enter it directly into MySQL Query Browser. But it just doesn't work when I run the exact same INSERT statement in PHP.
$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)
In MySQL Query Browser the "Table Options" tab shows that for this company_test table my charset is utf8.
Thanks.
mysql_*functions. They're being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you're not sure which one to use, read this SO article.currencyfield? I've no idea if a pound sign would be stored as one character or as something like£, which wouldn't fit....£is not an ASCII character. Inserting the record correctly will require matching your character sets in PHP, the database connection, and the database itself.