Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用PDO将数据写入数据库,给出奇怪的结果_Php_Mysql_Pdo - Fatal编程技术网

Php 用PDO将数据写入数据库,给出奇怪的结果

Php 用PDO将数据写入数据库,给出奇怪的结果,php,mysql,pdo,Php,Mysql,Pdo,我有以下连接PDO的代码: 这几行用于插入值: 但当我从数据库中获取数据时,UTF-8编码中的一些值,如$from,变得像0o_xd7sjnc,x。。。 你能告诉我怎么了吗? 我查看了一些其他帖子,bt没有找到正确的答案…PDO和mysql都没有修改过您的数据。 所以,这是因为我们在其他地方做了改动 顺便说一句,你可以用不太费力的方式编写你的函数 function InsertFileToDb($filename, $filetype, $recieve, $update, $from, $co

我有以下连接PDO的代码:

这几行用于插入值:

但当我从数据库中获取数据时,UTF-8编码中的一些值,如$from,变得像0o_xd7sjnc,x。。。 你能告诉我怎么了吗?
我查看了一些其他帖子,bt没有找到正确的答案…

PDO和mysql都没有修改过您的数据。 所以,这是因为我们在其他地方做了改动

顺便说一句,你可以用不太费力的方式编写你的函数

function InsertFileToDb($filename, $filetype, $recieve, $update, $from, $comment, $file) {
    $sql = "INSERT INTO assistance VALUES(NULL, ?, ?, ?, ?, ?, ?, ?)";
    $conn->prepare($sql)->execute(func_get_args());
}

可能是编码问题,所以您可以尝试以下步骤,看看会发生什么:

添加:$conn=newpdo'mysql:host=localhost;dbname=数据库;字符集=utf8','kkk','KKKK'

确保数据库表是utf8\U unicode\U ci


还可以将此添加到标记中的html页面:

您需要检查发送的表单。你能在插入数据库之前回显$from,看看结果是什么吗。我检查过了,这没问题…检查你的数据库字段类型-都是字符串吗?谢谢你,我计算出来了,我已经用它设置了排序规则:$PDO->execSET会话排序规则\连接='utf8 \波斯\ ci';;$PDO->execSET字符集“utf8”;;$PDO->execset名称utf8;谢谢大家
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));
function InsertFileToDb($filename, $filetype, $recieve, $update, $from, $comment, $file) {
    $sql = "INSERT INTO assistance VALUES(NULL, ?, ?, ?, ?, ?, ?, ?)";
    $conn->prepare($sql)->execute(func_get_args());
}