dongyu1125 2013-12-05 15:34
浏览 16
已采纳

用PDO将数据写入DB会产生奇怪的结果

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...

  • 写回答

2条回答 默认 最新

  • duankeng1911 2013-12-05 15:44
    关注

    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">

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接