【问题标题】:PDO execute: Array to String conversionPDO 执行:数组到字符串的转换
【发布时间】:2014-09-26 02:09:48
【问题描述】:

我收到一个数组到字符串的转换错误

errorCode() --> 00000

errorInfo() --> 数组

public function getUserInfoByMail( $userEmail )
{
    if (is_mail($userEmail))
    {
        $sql = $this->db->prepare("SELECT * FROM customer INNER JOIN addresses ON customer.customerid = addresses.customerid WHERE standard='1' AND deleted='0' AND email=:email");
        if ($sql->execute(array(':email' => $userEmail))) 
             return $sql->fetch(PDO::FETCH_ASSOC);
        else 
             throw new Exception("There was a DB-Error!");
    }
    //....
}

为什么我收到一个数组到字符串的转换错误?

【问题讨论】:

  • 所以$userEmail 可能是一个数组?
  • 阅读 php 手册以获取 errorInfo。它是一个包含 SQLState 错误、错误代码和错误消息的数组。 ch1.php.net/manual/en/pdo.errorinfo.php
  • 你能发布完整的错误信息吗?
  • 致命错误:未捕获的异常 'Exception' 带有消息 'There was a DB-Error!'在 C:\...\customer.dao.php:107 堆栈跟踪:#0 C:\...\login.php(107): CustomerDAO->getUserInfoByMail('test@test.com') #1 { main} 在 C:\...\customer.dao.php 第 107 行抛出

标签: php pdo


【解决方案1】:
->execute() expects you to send it an array with each element representing each ? in the query.\

问题的主要原因是仅发送 2 个元素,因此它使用数组作为第二个...请参阅 here

【讨论】:

    【解决方案2】:

    错误代码00000 表示,您没有错误。只需尝试将errorCode 转换为int,它将评估为假

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多