PHP Classes

File: src/query/SingleInsertQuery.php

Recommend this page to a friend!
  Classes of Vitaly   Queasy DB   src/query/SingleInsertQuery.php   Download  
File: src/query/SingleInsertQuery.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Queasy DB
Execute queries by accessing class variables
Author: By
Last change:
Date: 2 years ago
Size: 776 bytes
 

Contents

Class file image Download
<?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);
    }
}