I am trying to retrieve data from the database. I'm using PDO and the execute statement seems to be giving problems that I can't figure out.
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;
}
The queryDB
function in another class is given below:
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);
}
}
When I run in my browser, I get the following error
<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>