I am trying to use the following Query method in my db class to query the database with a prepared statement. The SQL appears to work fine in MySQL but in the prepared statement only works when there is one condition after the where but I need it to work with three conditions. Any help would be greatly appreciated.
DB Class - Query Method
// Generic query method.
public function query($sql, $params = array()) {
// reset to ensure an error from a previous query is not returned.
$this->_error = false;
if($this->_query = $this->_pdo->prepare($sql)) {
$x = 1;
if(count($params)) {
foreach($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
}
if($this->_query->execute()) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
// Calling query method
// Method to check if the activity is available at the requested date and time.
public function checkDateTimeAvailability($name, $date, $time) {
$result = $this->_db->query("SELECT * FROM `activity` WHERE name = ? AND act_date = ? AND
time_from = ?", array($name, $date, $time));
var_dump($result);
if(!empty($result)){
echo "query successful";
return true;
} else {
return false;
}
}