PDO查询未按预期执行

时间:2016-09-02 19:31:59

标签: php mysqli pdo

我正在尝试从数据库中检索数据。我正在使用PDO,执行语句似乎给出了我无法弄清楚的问题。

public function doesAdminEmailExist($email){
     $this->m_dbHandler->queryDB("SELECT id FROM Admin WHERE email = ? ", array($email));
     $ret = $this->m_dbHandler->fetchOne();

     if(!empty($ret)) return $ret["id"];
     else return -1;
}

下面给出了另一个类中的queryDB函数:

public function queryDB($query, $params=array()){
    try {
        $stmt = $this->m_dbConn->prepare($query);
        if($stmt === false){
            $arr = $this->m_dbConn->errorInfo();
            throw new Exception("Could not prepare query: ". $arr[2]." // query: ".$query);
        }
        else {
            $bool_status = $stmt->execute($params);
            if($bool_status){ // Query was successful
                $this->result = $stmt;
            }
            else { // Query was not successful
                $arr = $stmt->errorInfo();
                throw new Exception("Could not execute query: ". $arr[2]." // query: ".$query);
            }
        }
    }
    catch (Exception $e) {
        //throw $e;
        $arr = $this->m_dbConn->errorInfo();
        throw new Exception("An error occurred: ". $arr[2]." // query: ".$query);
    }

}

当我在浏览器中运行时,出现以下错误

<server_response>
  <return_status>true</return_status>
  <return_message>error Occured. Rethrowing <br>An   error occurred: // query: SELECT id FROM Admin WHERE email = ? </return_message>
</server_response>

0 个答案:

没有答案