dongyan3237 2015-04-26 13:47
浏览 73

传递非标准A-Z 0-9字符时PHP脚本不起作用

I have a PHP script:

<?php
$dbh = new PDO('sqlite:database.db');
$sth = $dbh->prepare('SELECT * FROM t1 WHERE user = :user');
$sth->bindParam(':user', $_POST['user'], PDO::PARAM_STR);
$sth->execute();
$result = $sth->fetchAll();
if( empty( $result ) )
{
     echo "0";
}
else
{
     echo "1";
}
?>

It works correctly when passed standard A-Z 0-9 characters but when $_POST['user'] is something like Çärmêñ™ it incorrectly returns 0. The user is present in the database so it should return 1.

How do I get it to work correctly?

Update

Yes as mentioned in the comments it appears that the database is the issue here:

sqlite> SELECT * FROM t1;
Çärmêñ™|098f6bcd4621d373cade4e832627b4f6
sqlite> 

sqlite> SELECT * FROM t1 WHERE user = 'Çärmêñ™';
sqlite> 

but the encoding is already set to UTF-8:

sqlite> PRAGMA encoding;
UTF-8
  • 写回答

1条回答 默认 最新

  • dongtaijue1578 2015-04-26 14:15
    关注

    try using to scape the strings from the $_POST variable using mysqli_real_scape_string.

    $user = mysqli_real_scape_string("conecction",$_POST['user']);
    

    then try with select : $sth = mysqli_query('SELECT * FROM t1 WHERE user = '$user');

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)