I'm trying to read a file with japanese characters and then insert them into the database. I'm currently getting an error in the mysql syntax being caused by the characters. Can anybody help me with this issue in guiding me in the right direction of storing utf8 characters.
PHP Code:
<?php
include_once("classes/Database.php");
header("Content-Type: text/plain; charset=UTF-8"); // output as text file
header("Content-Type: text/html; charset=UTF-8");
$file = fopen("address2.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
$db->query("SET NAMES utf8");
while(!feof($file))
{
$line = fgets($file);
$db->query("insert into hotels(address2) values('$line')");
}
fclose($file);
?>
Thanks
11-01-2012, 10:20 PM
NogDog
May just be that you are not escaping the input and are encountering a SQL injection error. Not sure which database extension you're using, but if it supports prepared statements with bound parameters, I'd suggest using that; if not, then use the applicable escaping function for that DB extension.