I have this code for connecting PDO:
$conn = new PDO('mysql:host = localhost; dbname = DataBase', 'kkk', 'kkkkkk');
if ( $conn ) { echo 'Connect Shodee'; }
} catch (PDOException $e) {
$e->error();
}
and this lines for INSERT the values:
function InsertFileToDb($filename, $filetype, $recieve, $update, $from, $comment, $file) {
$sql="INSERT INTO `DataBase`.`assistance`(`filename`,`filetype`,`recieve`,`update`,`from`,`comment`,`file`) VALUES(:filename, :filetype, :recieve, :update, :from, :comment, :file)";
$prepare = $conn->prepare($sql);
$result = $prepare->execute(array(
':filename'=>$filename, ':filetype'=>$filetype, ':recieve'=>$recieve,
':update'=>$update, ':from'=>$from, ':comment'=>$comment, ':file'=>$file));
but when I fetch the data from my DB, some values like $from
that is in UTF-8 encoding become just like 0o_xd7sjnc,x
...
would you tell me what is wrong?
I checked HERE and HERE and some other posts bt didn't find the right answer...
Maybe it's an encoding problem, so you could try these steps and see what happens:
Add this: $conn = new PDO('mysql:host=localhost;dbname=Database;charset=utf8','kkk', 'kkkkkk');
Make sure that your database tables are utf8_unicode_ci
Also add this to your html page in the <head>
tag: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Neither PDO nor mysql ever alter your data.
So, it's rather were altered somewhere else.
By the way, you can write your function less toilsome way
function InsertFileToDb($filename, $filetype, $recieve, $update, $from, $comment, $file) {
$sql = "INSERT INTO assistance VALUES(NULL, ?, ?, ?, ?, ?, ?, ?)";
$conn->prepare($sql)->execute(func_get_args());
}