コード例 #1
0
ファイル: MPDOQuery.php プロジェクト: mpstyle/mtoolkit
 /**
  * Executes a previously prepared SQL query. Returns true if the query 
  * executed successfully; otherwise returns false.<br />
  * Note that the last error for this query is reset when exec() is called.
  * 
  * @return boolean
  */
 public function exec()
 {
     /* @var $sqlStmt \PDOStatement */
     $sqlStmt = $this->getConnection()->prepare($this->getQuery());
     if ($sqlStmt === false) {
         $errorInfo = $this->getConnection()->errorInfo();
         parent::setLastError(new MSqlError($errorInfo[2], (string) $errorInfo[1], ErrorType::CONNECTION_ERROR, $this->getConnection()->errorCode()));
         $this->result = new MPDOResult($sqlStmt);
         return false;
     }
     // Bind input
     foreach ($this->bindedValues as $i => $bindedValue) {
         $type = $this->getPDOType($bindedValue);
         if ($type === false) {
             throw new \Exception('Invalid type of binded value at position ' . ($i + 1) . '.');
         }
         $bindParamsResult = $sqlStmt->bindValue($i + 1, $bindedValue, $type);
         if ($bindParamsResult === false) {
             $errorInfo = $sqlStmt->errorInfo();
             parent::setLastError(new MSqlError($errorInfo[2], (string) $errorInfo[1], ErrorType::STATEMENT_ERROR, $sqlStmt->errorCode()));
             return false;
         }
     }
     // Exec query
     $result = $sqlStmt->execute();
     if ($result == false) {
         $errorInfo = $sqlStmt->errorInfo();
         parent::setLastError(new MSqlError($errorInfo[2], (string) $errorInfo[1], ErrorType::STATEMENT_ERROR, $sqlStmt->errorCode()));
         return false;
     }
     $this->result = new MPDOResult($sqlStmt);
     $sqlStmt->closeCursor();
     return true;
 }
コード例 #2
0
ファイル: MSqlQueryModel.php プロジェクト: mpstyle/mtoolkit
 /**
  * Reimplemented from MAbstractDataModel::rowCount().
  * 
  * @return int
  */
 public function rowCount()
 {
     return $this->query->getResult()->rowCount();
 }
コード例 #3
0
ファイル: MPDOQuery.php プロジェクト: mtoolkit/mtoolkit-model
 private function execFails(\PDOStatement $sqlStmt, $errorType)
 {
     $errorInfo = $sqlStmt->errorInfo();
     parent::setLastError(new MSqlError($errorInfo[2], (string) $errorInfo[1], $errorType, $sqlStmt->errorCode()));
     $this->result = new MPDOResult(new \PDOStatement(), $this);
     return false;
 }