【问题标题】:Weirds characters with PDOException error带有 PDOException 错误的奇怪字符
【发布时间】:2017-10-03 14:14:18
【问题描述】:

我在 CentOS 7 上使用 PHP 5.6 运行 MariaDB。 这是我的连接字符串:

try {
   $connStr = 'mysql:host=server;dbname=mysql';
   $pdo = new PDO($connStr, 'user', 'passwd');
   $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   $pdo->exec('SET NAMES utf8');
catch(PDOException $err) {
   var_dump($err->getMessage());
   die();
}

一切正常,没有编码问题,除了引发一些奇怪字符的 PDO 错误:

MUH��/NU(~�03��D!71G�����J����̜��*��+S��+S��N|5

我该如何管理?

【问题讨论】:

  • 在here中寻找“黑钻”
  • 问题是它只发生在 SQL 错误消息中。数据得到正确处理

标签: php mysql pdo encoding error-handling


【解决方案1】:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 接近 html 页面的开头

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2014-10-06
    • 2014-05-24
    相关资源
    最近更新 更多