<?php
namespace queasy\db\query;
class SingleInsertQuery extends TableQuery
{
/**
* Execute INSERT query.
*
* @param array $params Query parameters
*
* @return int Insert id generated by database
*
* @throws DbException On error
*/
public function run(array $params = array(), array $options = array())
{
$sql = sprintf('
INSERT INTO `%s`',
$this->tableName()
);
$sql = count($params)
? sprintf('
%s
VALUES (%s)',
$sql,
rtrim(str_repeat('?, ', count($params)), ', '))
: $sql . ' DEFAULT VALUES';
$this->setSql($sql);
return parent::run($params, $options);
}
}
|