Index

InsertStatement

MMO\pdo\statements · 1 symbol · generated 5 Oct 2026

class

InsertStatement

InsertStatement.php:32

INSERT INTO table (cols) VALUES (…), (…) [ON DUPLICATE/CONFLICT …]

class MMO\pdo\statements\InsertStatement extends MMO\pdo\statements\Statement
Namespace
MMO\pdo\statements
Extends
Statement
The column list is fixed by the first row added; later rows are aligned onto it (a column a later row does not mention is inserted as NULL), so one statement can insert many rows in a single round trip.
$stmt = $handler->insertStatement('user') ->values(['name' => 'marc', 'email' => 'marc@x.com']) ->values(['name' => 'bob', 'email' => 'bob@x.com']) ->duplicate(['name' => true, 'email' => false]);//name is the key, email gets overwritten on conflict $stmt->execute();

Index

COLUMNS_KEY
DUPLICATE_KEY
ROWS_KEY
TABLE_KEY
columns($columns)Declare the column list up front -- only needed to insert columns the first row does not mention.
countRows()
delayed($value)
duplicate($fields)Turn this into an upsert: on a key conflict, update the non-key columns instead of failing.
getColumns()
highPriority($value)
ignore($value)
into($name)
lowPriority($value)
realign()Make every row carry exactly the statement's columns, in order.
values($values)Add one row.
__construct($handler, $table, $values)

Constants4

COLUMNS_KEY

const COLUMNS_KEY = 'columns'

DUPLICATE_KEY

const DUPLICATE_KEY = 'duplicate'

ROWS_KEY

const ROWS_KEY = 'rows'

TABLE_KEY

const TABLE_KEY = 'table'

Methods12

columns($columns)

InsertStatement.php:66

Declare the column list up front -- only needed to insert columns the first row does not mention.

function columns(array $columns): self
$columnsarray
returnsself

duplicate($fields)

InsertStatement.php:129

Turn this into an upsert: on a key conflict, update the non-key columns instead of failing.

function duplicate(?array $fields): selfBoth dialects are supported; the driver decides which is rendered (`ON DUPLICATE KEY UPDATE` for MySQL, `ON CONFLICT(keys) DO UPDATE SET` for SQLite).
$fieldsnull | arraycolumn => is it part of the conflicting key. Null clears the upsert.
returnsself
$stmt->duplicate(['name' => true, 'email' => true, 'level' => false]);

realign()

InsertStatement.php:108

Make every row carry exactly the statement's columns, in order.

protected function realign(): self
returnsself

values($values)

InsertStatement.php:93

Add one row.

function values(array $values): selfA key may carry a bind type: `'age:int'` binds as an integer, and `'counter:raw'` renders the value as a SQL expression instead of binding it ([`Statement::SplitType`](https://mcp.mmoframework.fr/documentation/mmo.pdo/php/statements/Statement.md#statement-splittype)). WARNING for multi-row inserts: one INSERT has a single column list, so it is the union of every row's keys, and a row that does not mention one of them inserts an explicit NULL -- which overrides that column's `DEFAULT` and fails outright on a `NOT NULL DEFAULT …` column. Give every row the same keys, or use one statement per shape. A column NO row mentions is simply left out, so its default does apply.
$valuesarraycolumn => value
returnsself
Inherited members (53)
ConstantsDeclared byDescription
ALL_FLAGStatement
CREATE_IF_NOT_EXISTS_FLAGStatement
CREATE_TEMPORARY_FLAGStatement
DELAYED_FLAGStatement
DISTINCT_FLAGStatement
DISTINCT_ROW_FLAGStatement
HIGH_PRIORITY_FLAGStatement
IF_EXISTS_FLAGStatement
IGNORE_FLAGStatement
LOW_PRIORITY_FLAGStatement
QUICK_FLAGStatement
STRAIGHT_JOIN_FLAGStatement
PropertiesDeclared byDescription
contentStatement
handlerStatement
optsStatement
stmtStatement
templateStatement
MethodsDeclared byDescription
addOptions($opts, $appendList)StatementMerge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions.
bindValue($pdo, $index, $value, $type, $binds)StatementBind one already-emitted value onto the PDO statement.
clear()StatementEmpty the underlying content, keeping the object itself.
clearOptions()StatementEmpty the options bag.
count()Statement\Countable::count
execute()StatementExecute the query and set the current statement
fetch($opt)StatementFetch the first row of the query's result
fetchAll($clear)StatementFetch all the result of a query
fetchAllObjects($class, $constructFirst, $args, $clear)StatementFetch all the result of a query as Objects.
fetchObject($class, $constructFirst, $args)StatementFetch the result of a query as an Object.
fetchValue($key)StatementFetch the column's value of the first row of the query's result and advance fetch pointer
fetchValues($key)StatementFetch the column's value of all the row of the query's result
flag($key, $flag, $set)Statement
getIterator()Statement\IteratorAggregate::getIterator
getOption($key, $default)Statement
getOptions()Statement
getPDOStatement()Statement
getPlaceholders()StatementExtract placeholder from template
isEmpty()Statement
jsonSerialize()Statement\JsonSerializable::jsonSerialize -- the raw content is returned as-is (not recursively converted), so json_encode() relies on any nested iArray values being JsonSerializable themselves.
keys()Statement
loadArray($data)StatementLoad every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g.
offsetExists($key)Statement\ArrayAccess::offsetExists
offsetGet($key)Statement\ArrayAccess::offsetGet
offsetSet($key, $value)Statement\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.
offsetUnset($key)Statement\ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain …
prepare($binds, $sql)StatementPrepare a PDO statement by binding values.
push($key, $fields)Statement
render($opts)Statement
reset()Statement
rowCount()Statement
setOption($key, $value)StatementSet (or, with a null $value, remove) a single option.
setOptions($opts)StatementReplace the whole options bag.
SplitType($key)StatementSplit a column:type key used by the INSERT/UPDATE value lists.
toArray()StatementConvert the content to a plain array, recursively converting any nested iArray value (e.g.
__toString()Statement