doulei8861 2014-11-28 11:03
浏览 51

PHP PDO中的特殊字符Sqlite Query导致无法识别的令牌

I try to execute a query in PHP using PDO on Sqlite which may contain special characters (Ä,Ö,Ü,...). But I fail to execute the query. PHP returns the following Error:

array(3) { [0]=> string(5) "00000" [1]=> int(1) [2]=> string(35) "unrecognized token: "'MÄÖÜ123DE"" }

I tried to execute the query native and also in the way to use preparing statement and binding values.

$statement = "select * from list where param = ? and value = ?";
        $stmt = $db->prepare($statement);
        $stmt->bindValue(1, $setparam);
        $stmt->bindValue(2, $val,PDO::PARAM_STR);
        $stmt->execute();

Native way:

$statement = "select * from list where param = '".$setparam."' and value = '".$val."'";
        $res = $db->query($statement);

Both ways return the same error. I use XAMPP 1.8.3-5. The used coding ist UTF-8. In sqlitestudio the query works well.

EDIT Execute PDO:

$db = new PDO("sqlite:database/lists.db","","",array(
                PDO::ATTR_PERSISTENT => true));

The used UTF-8 HTML meta execution:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  • 写回答

1条回答

  • dongmeng9048 2014-11-28 19:19
    关注

    It happen that the database still set by default to use ISO-8859-15. Try to execute this query before any other to fix encoding settings

    SET NAMES "utf8"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题