Db::execute PHP Method

execute() public method

执行语句 针对 INSERT, UPDATE 以及DELETE
public execute ( string $str ) : integer
$str string sql指令
return integer
    public function execute($str)
    {
        try {
            $this->queryStr = $str;
            $this->numRows = Capsule::getReadPdo()->exec($str);
            $this->lastInsID = Capsule::getReadPdo()->lastInsertId();
            $this->debug();
            return $this->numRows;
        } catch (PDOException $e) {
            $this->error = $e->getMessage();
        }
        return false;
        // // return Capsule::select($str);
        // $this->initConnect(true);
        // if (!$this->_linkID) {
        //     return false;
        // }
        // $this->queryStr = $str;
        // //释放前次的查询结果
        // if ($this->queryID) {
        //     $this->free();
        // }
        // $this->W(1);
        // // var_dump($str);exit;
        // $result =   mysql_query($str, $this->_linkID) ;
        // $this->debug();
        // if (false === $result) {
        //     $this->error();
        //     return false;
        // } else {
        //     $this->numRows = mysql_affected_rows($this->_linkID);
        //     $this->lastInsID = mysql_insert_id($this->_linkID);
        //     return $this->numRows;
        // }
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $key
  */
 public function set($guildID, $key, $value)
 {
     $json = $this->getAll($guildID);
     $json->{$key} = $value;
     $data = json_encode($json);
     $this->db->execute("INSERT INTO settings (serverID, settings) VALUES (:serverID, :settings) ON DUPLICATE KEY UPDATE settings = :settings", array(":serverID" => $guildID, ":settings" => $data));
 }
All Usage Examples Of Db::execute