PDO Query方法仅在where子句中的一个条件下工作

时间:2015-01-05 00:22:14

标签: php mysql pdo

我试图在我的db类中使用以下Query方法来使用预准备语句查询数据库。 SQL似乎在MySQL中正常工作,但在准备好的语句中只有在where之后有一个条件但我需要它才能使用三个条件时才能工作。任何帮助将不胜感激。

数据库类 - 查询方法

// 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;
    }
}   

0 个答案:

没有答案