File: src/query/SingleNamedInsertQuery.php

Recommend this page to a friend!
  Classes of Vitaly  >  Queasy DB  >  src/query/SingleNamedInsertQuery.php  >  Download  
File: src/query/SingleNamedInsertQuery.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: 6 months ago
Size: 980 bytes
 

Contents

Class file image Download
<?php

namespace queasy\db\query;

class
SingleNamedInsertQuery extends TableQuery
{
   
/**
     * Execute INSERT query with named parameters.
     *
     * @param array $params Query parameters (key - value array)
     *
     * @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` (%s)
            VALUES (%s)'
,
           
$this->tableName(),
           
implode(', ',
               
array_map(function($paramName) {
                    return
'`' . $paramName . '`';
                },
array_keys($params))
            ),
           
implode(', ',
               
array_map(function($paramName) {
                    return
':' . $paramName;
                },
array_keys($params))
            )
        );

       
$this->setSql($sql);

        return
parent::run($params, $options);
    }
}


For more information send a message to info at phpclasses dot org.