Ouzo\Db\QueryExecutor::prepare PHP Method

prepare() public static method

public static prepare ( $db, $query ) : QueryExecutor | EmptyQueryExecutor
$db
$query
return QueryExecutor | EmptyQueryExecutor
    public static function prepare($db, $query)
    {
        if (empty($db) || !$db instanceof Db) {
            throw new InvalidArgumentException("Database handler not provided or is of wrong type");
        }
        if (!$query) {
            throw new InvalidArgumentException("Query object not provided");
        }
        if (!$query->table) {
            throw new InvalidArgumentException("Table name cannot be empty");
        }
        if (self::isEmptyResult($query)) {
            return new EmptyQueryExecutor();
        }
        return new QueryExecutor($db, $query);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Runs an update query against a set of models
  * @param array $attributes
  * @return int
  */
 public function update(array $attributes)
 {
     $this->_query->type = QueryType::$UPDATE;
     $this->_query->updateAttributes = $attributes;
     return QueryExecutor::prepare($this->_db, $this->_query)->execute();
 }
All Usage Examples Of Ouzo\Db\QueryExecutor::prepare