Php PDO查询,已准备好和语句

Php PDO查询,已准备好和语句,php,mysql,oop,pdo,Php,Mysql,Oop,Pdo,使用OOP PDO DB包装器,尝试将其设置为可以向查询中添加和语句,而无需进行多个查询,但由于某些原因,这不起作用,但无法提供 public function query($sql, $params = array()){ $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)){ $x = 1; if(count($params))

使用OOP PDO DB包装器,尝试将其设置为可以向查询中添加
语句,而无需进行多个查询,但由于某些原因,这不起作用,但无法提供

    public function query($sql, $params = array()){
    $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;
}

public function action($action, $table, $where = array(), $additional = array()){
    if(count($where) === 3){
        $operators = array('=', '>', '<', '>=', '<=');

        $field = $where[0];
        $operator = $where[1];
        $value = $where[2];
        if(count($additional) === 4) {
            $condition = $additional[0];
            $field2 = $additional[1];
            $operator2 = $additional[2];
            $value2 = $additional[3];
        }

        if(in_array($operator, $operators)){
            if(count($additional) === 4){
                $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ? {$condition} {$field2} {$operator2} ?";
                if(!$this->query($sql, array($value, $value2))->error()){
                    return $this;
                }
            } else {
                $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
                if(!$this->query($sql, array($value))->error()){
                    return $this;
                }
            }

        }
    }
    return false;
}

public function get($table, $where, $additional = array()){
    return $this->action('SELECT *', $table, $where, $additional);
}
这就是我所说的

<?php for($i = 0;$i <= 6;$i++){ ?>
        <div id="<?php echo $days[$i];?>" class="tab-pane <?php if ($i == $today) { echo "active"; }?>">
            <?php
            $timetable = new Timetable();
            $timetable->get($days[$i]);
            echo $days[$i];
            if(!empty($timetable->data())) {
                foreach ($timetable->data() as $day) {
                    print_r($day);
                }
            }
            ?>
        </div>
    <?php } ?>

问:你能发布一个SQL的例子吗?我试着按照“从
timeline
WHERE
day
='Monday'和
week
=3”的思路来做一些事情,不管它是什么(SQL),正确地添加问题,而不是添加注释。它是从$timeline->get($days[$I])创建查询的,它将输入函数“public function get($time)”,然后该函数使用使用动作块的第一个代码块中的get函数。
<?php for($i = 0;$i <= 6;$i++){ ?>
        <div id="<?php echo $days[$i];?>" class="tab-pane <?php if ($i == $today) { echo "active"; }?>">
            <?php
            $timetable = new Timetable();
            $timetable->get($days[$i]);
            echo $days[$i];
            if(!empty($timetable->data())) {
                foreach ($timetable->data() as $day) {
                    print_r($day);
                }
            }
            ?>
        </div>
    <?php } ?>
SELECT * FROM timetable WHERE day = 'Monday' AND week = 3