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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料