lib/QueryBuilder/Insert.php
public function buildQuery(string $table, array $colVals): SqlParams
    {
        self::validateColValsStructure($colVals);

        $columns = $this->escapeColumns(array_keys($colVals[0]));
        $insert = "INSERT INTO {$table} (" . implode(', ', $columns) . ')';

        $valSetStr = ' (' . str_repeat('?,', count($columns) - 1) . '?),';
        $valStr = ' VALUES' . substr_replace(str_repeat($valSetStr, count($colVals)), '', -1); // remove trailing comma
        $params = array_merge(...array_map('array_values', $colVals));

        if ($this->options instanceof \PeachySQL\SqlServer\Options) {
            $selStr = '; SELECT SCOPE_IDENTITY() AS RowID;';
        } else {
            $selStr = '';
        }

        return new SqlParams($insert . $valStr . $selStr, $params);
    }
public function buildQuery(string $table, array $colVals): SqlParams
    {
        self::validateColValsStructure($colVals);

        $columns = $this->escapeColumns(array_keys($colVals[0]));
        $insert = "INSERT INTO {$table} (" . implode(', ', $columns) . ')';

        $valSetStr = ' (' . str_repeat('?,', count($columns) - 1) . '?),';
        $valStr = ' VALUES' . substr_replace(str_repeat($valSetStr, count($colVals)), '', -1); // remove trailing comma
        $params = array_merge(...array_map('array_values', $colVals));

        if ($this->options instanceof \PeachySQL\SqlServer\Options) {
            $selStr = '; SELECT SCOPE_IDENTITY() AS RowID;';
        } else {
            $selStr = '';
        }

        return new SqlParams($insert . $valStr . $selStr, $params);
    }
public function buildQuery ( string $ table , array $ colVals ) : SqlParams { self :: validateColValsStructure ( $ colVals ) ; $ columns = $ this -> escapeColumns ( array_keys ( $ colVals [ 0 ] ) ) ; $ insert = "INSERT INTO {$table} (" . implode ( ', ' , $ columns ) . ')' ; $ valSetStr = ' (' . str_repeat ( '?,' , count ( $ columns ) - 1 ) . '?),' ; $ valStr = ' VALUES' . substr_replace ( str_repeat ( $ valSetStr , count ( $ colVals ) ) , '' , - 1 ) ; // remove trailing comma $ params = array_merge ( ... array_map ( 'array_values' , $ colVals ) ) ; if ( $ this -> options instanceof \ PeachySQL \ SqlServer \ Options ) { $ selStr = '; SELECT SCOPE_IDENTITY() AS RowID;' ; } else { $ selStr = '' ; } return new SqlParams ( $ insert . $ valStr . $ selStr , $ params ) ; }
Generates an INSERT query with placeholders for values
Generates an INSERT query with placeholders for values