Overview

Namespaces

  • CzProject
    • SqlGenerator
      • Drivers
      • Statements

Classes

  • CzProject\SqlGenerator\Drivers\MysqlDriver
  • CzProject\SqlGenerator\Helpers
  • CzProject\SqlGenerator\SqlDocument
  • CzProject\SqlGenerator\Statements\AddColumn
  • CzProject\SqlGenerator\Statements\AddForeignKey
  • CzProject\SqlGenerator\Statements\AddIndex
  • CzProject\SqlGenerator\Statements\AlterTable
  • CzProject\SqlGenerator\Statements\ColumnDefinition
  • CzProject\SqlGenerator\Statements\CreateTable
  • CzProject\SqlGenerator\Statements\DropColumn
  • CzProject\SqlGenerator\Statements\DropForeignKey
  • CzProject\SqlGenerator\Statements\DropIndex
  • CzProject\SqlGenerator\Statements\DropTable
  • CzProject\SqlGenerator\Statements\ForeignKeyDefinition
  • CzProject\SqlGenerator\Statements\IndexColumnDefinition
  • CzProject\SqlGenerator\Statements\IndexDefinition
  • CzProject\SqlGenerator\Statements\Insert
  • CzProject\SqlGenerator\Statements\ModifyColumn
  • CzProject\SqlGenerator\Statements\RenameTable

Interfaces

  • CzProject\SqlGenerator\IDriver
  • CzProject\SqlGenerator\IStatement

Exceptions

  • CzProject\SqlGenerator\DuplicateException
  • CzProject\SqlGenerator\Exception
  • CzProject\SqlGenerator\InvalidArgumentException
  • CzProject\SqlGenerator\NotImplementedException
  • CzProject\SqlGenerator\NotSupportedException
  • CzProject\SqlGenerator\OutOfRangeException
  • CzProject\SqlGenerator\StaticClassException
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 
<?php

    namespace CzProject\SqlGenerator\Statements;

    use CzProject\SqlGenerator\Helpers;
    use CzProject\SqlGenerator\IDriver;
    use CzProject\SqlGenerator\IStatement;


    class Insert implements IStatement
    {
        /** @var string */
        private $tableName;

        /** @var array */
        private $data;


        /**
         * @param  string
         * @param  array
         */
        public function __construct($tableName, array $data)
        {
            $this->tableName = $tableName;
            $this->data = $data;
        }


        /**
         * @return string
         */
        public function toSql(IDriver $driver)
        {
            $output = 'INSERT INTO ' . $driver->escapeIdentifier($this->tableName);

            // columns
            $output .= ' (';
            $output .= implode(', ', array_map(array($driver, 'escapeIdentifier'), array_keys($this->data)));
            $output .= ")\nVALUES (";

            // data
            $fields = count($this->data);

            foreach ($this->data as $value) {
                $output .= Helpers::formatValue($value, $driver);
                $fields--;

                if ($fields > 0) {
                    $output .= ', ';
                }
            }

            $output .= ');';
            return $output;
        }
    }
czproject/sql-generator v1.0.1 API documentation API documentation generated by ApiGen