/    Sign up×
Community /Pin to ProfileBookmark

UTF-8 Character issues

Hi,

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.

[code=php]<?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);

?>[/code]

Thanks

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 02.2012 — 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.
×

Success!

Help @sc_king spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...