Insert
extends Statement
in package
Uses
Select, Set, Values
Class Insert.
Tags
Table of Contents
- OPT_DELAYED = 'DELAYED'
- OPT_HIGH_PRIORITY = 'HIGH_PRIORITY'
- OPT_IGNORE = 'IGNORE'
- Convert errors to warnings, which will not stop inserts of additional rows.
- OPT_LOW_PRIORITY = 'LOW_PRIORITY'
- $database : Database
- $sql : array<string|int, mixed>
- SQL clauses and parts.
- __construct() : mixed
- Statement constructor.
- __toString() : string
- columns() : static
- Sets the INTO columns.
- into() : static
- Sets the INTO table.
- onDuplicateKeyUpdate() : static
- Sets the ON DUPLICATE KEY UPDATE part.
- options() : static
- Sets the statement options.
- reset() : static
- Resets SQL clauses and parts.
- run() : int|string
- Runs the INSERT statement.
- select() : static
- Sets the SELECT statement part.
- set() : static
- Sets the SET clause.
- sql() : string
- Renders the INSERT statement.
- values() : static
- Adds a row of values to the VALUES clause.
- checkRowStatementsConflict() : void
- Check for conflicts in the INSERT statement.
- hasOptions() : bool
- Tells if the statement has options set.
- hasSet() : bool
- Tells if the SET clause was set.
- renderAliasedIdentifier() : string
- Renders a column part with an optional alias name, AS clause.
- renderAssignment() : string
- Renders an assignment part.
- renderColumns() : string|null
- Renders the INTO $table "(...$columns)" part.
- renderIdentifier() : string
- Renders a column part.
- renderInto() : string
- Renders the "INTO $table" clause.
- renderLimit() : string|null
- Renders the LIMIT clause.
- renderOnDuplicateKeyUpdate() : string|null
- Renders the ON DUPLICATE KEY UPDATE part.
- renderOptions() : string|null
- renderSelect() : string|null
- renderSet() : string|null
- Renders the SET clause.
- renderSetCheckingConflicts() : string|null
- Renders the SET clause checking conflicts.
- renderValue() : float|int|string
- Renders a subquery or quote a value.
- renderValues() : string|null
- Renders the VALUES clause.
- setLimit() : static
- Sets the LIMIT clause.
- subquery() : string
- Returns an SQL part between parentheses.
Constants
OPT_DELAYED
public
string
OPT_DELAYED
= 'DELAYED'
Tags
OPT_HIGH_PRIORITY
public
string
OPT_HIGH_PRIORITY
= 'HIGH_PRIORITY'
Tags
OPT_IGNORE
Convert errors to warnings, which will not stop inserts of additional rows.
public
string
OPT_IGNORE
= 'IGNORE'
Tags
OPT_LOW_PRIORITY
public
string
OPT_LOW_PRIORITY
= 'LOW_PRIORITY'
Tags
Properties
$database
protected
Database
$database
$sql
SQL clauses and parts.
protected
array<string|int, mixed>
$sql
= []
Methods
__construct()
Statement constructor.
public
__construct(Database $database) : mixed
Parameters
- $database : Database
Return values
mixed —__toString()
public
__toString() : string
Return values
string —columns()
Sets the INTO columns.
public
columns(string $column, string ...$columns) : static
Parameters
- $column : string
-
Column name
- $columns : string
-
Extra column names
Return values
static —into()
Sets the INTO table.
public
into(string $table) : static
Parameters
- $table : string
-
Table name
Return values
static —onDuplicateKeyUpdate()
Sets the ON DUPLICATE KEY UPDATE part.
public
onDuplicateKeyUpdate(array<string, \Closure|float|int|string|null>|object $columns) : static
Parameters
- $columns : array<string, \Closure|float|int|string|null>|object
-
Column name as key/property, column value/expression as value
Tags
Return values
static —options()
Sets the statement options.
public
options(string $option, string ...$options) : static
Parameters
- $option : string
-
One of the OPT_* constants
- $options : string
-
Each option value must be one of the OPT_* constants
Return values
static —reset()
Resets SQL clauses and parts.
public
reset([string|null $sql = null ]) : static
Parameters
- $sql : string|null = null
-
A part name or null to reset all
Tags
Return values
static —run()
Runs the INSERT statement.
public
run() : int|string
Return values
int|string —The number of affected rows
select()
Sets the SELECT statement part.
public
select(Closure $select) : static
Parameters
- $select : Closure
Tags
Return values
static —set()
Sets the SET clause.
public
set(array<string, \Closure|float|int|string|null>|object $columns) : static
Parameters
- $columns : array<string, \Closure|float|int|string|null>|object
-
Array of columns => values or an object to be cast to array
Return values
static —sql()
Renders the INSERT statement.
public
sql() : string
Return values
string —values()
Adds a row of values to the VALUES clause.
public
values(array<string|int, array<string|int, mixed>>|Closure|float|int|string|null $value, Closure|float|int|string|null ...$values) : static
Parameters
- $value : array<string|int, array<string|int, mixed>>|Closure|float|int|string|null
- $values : Closure|float|int|string|null
Return values
static —checkRowStatementsConflict()
Check for conflicts in the INSERT statement.
protected
checkRowStatementsConflict() : void
Tags
Return values
void —hasOptions()
Tells if the statement has options set.
protected
hasOptions() : bool
Return values
bool —hasSet()
Tells if the SET clause was set.
protected
hasSet() : bool
Return values
bool —True if was set, otherwise false
renderAliasedIdentifier()
Renders a column part with an optional alias name, AS clause.
protected
renderAliasedIdentifier(array<string, \Closure|string>|Closure|string $column) : string
Parameters
- $column : array<string, \Closure|string>|Closure|string
-
The column name, a subquery or an array where the index is the alias and the value is the column/subquery
Return values
string —renderAssignment()
Renders an assignment part.
protected
renderAssignment(string $identifier, Closure|float|int|string|null $expression) : string
Parameters
- $identifier : string
-
Identifier/column name
- $expression : Closure|float|int|string|null
-
Expression/value
Tags
Return values
string —renderColumns()
Renders the INTO $table "(...$columns)" part.
protected
renderColumns() : string|null
Return values
string|null —The imploded columns or null if none was set
renderIdentifier()
Renders a column part.
protected
renderIdentifier(Closure|string $column) : string
Parameters
- $column : Closure|string
-
The column name or a subquery
Return values
string —renderInto()
Renders the "INTO $table" clause.
protected
renderInto() : string
Tags
Return values
string —renderLimit()
Renders the LIMIT clause.
protected
renderLimit() : string|null
Return values
string|null —renderOnDuplicateKeyUpdate()
Renders the ON DUPLICATE KEY UPDATE part.
protected
renderOnDuplicateKeyUpdate() : string|null
Return values
string|null —The part or null if it was not set
renderOptions()
protected
renderOptions() : string|null
Return values
string|null —renderSelect()
protected
renderSelect() : string|null
Return values
string|null —renderSet()
Renders the SET clause.
protected
renderSet() : string|null
Return values
string|null —The SET clause null if it was not set
renderSetCheckingConflicts()
Renders the SET clause checking conflicts.
protected
renderSetCheckingConflicts() : string|null
Tags
Return values
string|null —The SET part or null if it was not set
renderValue()
Renders a subquery or quote a value.
protected
renderValue(Closure|float|int|string|null $value) : float|int|string
Parameters
- $value : Closure|float|int|string|null
-
A Closure for subquery, other types to quote
Return values
float|int|string —renderValues()
Renders the VALUES clause.
protected
renderValues() : string|null
Return values
string|null —The VALUES part or null if none was set
setLimit()
Sets the LIMIT clause.
protected
setLimit(int $limit[, int|null $offset = null ]) : static
Parameters
- $limit : int
- $offset : int|null = null
Tags
Return values
static —subquery()
Returns an SQL part between parentheses.
protected
subquery(Closure $subquery) : string
Parameters
- $subquery : Closure
-
A Closure having the current Manipulation instance as first argument. The returned value must be scalar