Example #1
0
 /**
  * @param $sql
  * @param mixed ... parameters for replace placeholders
  * @return array
  */
 public function query($sql)
 {
     $sourceQuery = Query::createByArray(func_get_args());
     $query = $this->transformQuery($sourceQuery);
     $result = $this->getAdapter()->execute($query);
     if (!empty($this->errorHandler)) {
         $error = $this->getPreparedErrorMessage($sourceQuery);
         if (!empty($error)) {
             call_user_func_array($this->errorHandler, $error);
             return false;
         }
     }
     if (preg_match('/^\\s*INSERT \\s+/six', $query->getQueryAsText())) {
         return $this->adapter->getLastInsertId();
     }
     if (preg_match('/^\\s*DELETE|UPDATE \\s+/six', $query->getQueryAsText())) {
         return $this->adapter->getRowsCountAffectedInLastQuery();
     }
     return $result;
 }