Db::query PHP Method

query() public method

执行查询 主要针对 SELECT, SHOW 等指令 返回数据集
public query ( string $str ) : mixed
$str string sql指令
return mixed
    public function query($str)
    {
        try {
            // $sth = Capsule::getReadPdo()->prepare($str);
            // var_dump($sth);exit;
            $this->queryStr = $str;
            $pdos = Capsule::getReadPdo()->query($str);
            $this->debug();
            $this->numRows = $pdos->rowCount();
            return $pdos->fetchAll(PDO::FETCH_ASSOC);
        } catch (PDOException $e) {
            $this->error = $e->getMessage();
        }
        return false;
        // // var_dump(Capsule::getReadPdo()->query('show tablesa'));exit;
        // return Capsule::select($str);
        // $this->initConnect(false);
        // if (!$this->_linkID) {
        //     return false;
        // }
        // $this->queryStr = $str;
        // //释放前次的查询结果
        // if ($this->queryID) {
        //     $this->free();
        // }
        // $this->Q(1);
        // // var_dump($str);exit;
        // // var_dump(Capsule::select($str));
        // $this->queryID = mysql_query($str, $this->_linkID);
        // $this->debug();
        // if (false === $this->queryID) {
        //     $this->error();
        //     return false;
        // } else {
        //     $this->numRows = mysql_num_rows($this->queryID);
        //     // var_dump($this->numRows);exit;
        //     return $this->getAll();
        // }
    }

Usage Example

Example #1
0
 public function brisi()
 {
     $db = new Db();
     $sql = "DROP TABLE IF EXISTS " . $this->studenti;
     $db->query($sql);
     $sql = "DROP TABLE IF EXISTS " . $this->kolokvij;
     $db->query($sql);
     $sql = "DROP TABLE IF EXISTS " . $this->ispit;
     $db->query($sql);
     $sql = "DROP TABLE IF EXISTS " . $this->grupe;
     $db->query($sql);
 }
All Usage Examples Of Db::query