Index

Table

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

class

Table

Table.php:41

Helper to create PDO query on Table

class MMO\pdo\helpers\Table
Namespace
MMO\pdo\helpers

Index

ENTITY_NAMESPACENamespace the generated entity classes (generateEntityClass) are declared in.
autoIdThe name of the primary column carrying AUTO_INCREMENT, or null if there is none.
entityClass
extra
fields
handler
ids
liaisons
nameTable name
addFields($fields)
clearFields()
count($filter)
create($ifNotExists)
createCollection($repo)
createStatement($ifNotExists)Create a CREATE TABLE query
delete($filter, $limit, $allowAll)Delete the rows matching $filter.
deleteStatement($filter, $limit)
drop($ifExists)
dropStatement($ifExists)
exists()
generateEntityClass()
getAutoId()
getEntityClass()
getExtra()
getFields()
getHandler()
getIds()
getName($withPrefix)
hasField($name)
insert($models)Insert one or more rows.
insertStatement($models)Build an INSERT for one or more rows.
query($repo, $filter, $fields, $sort, $limit, $offset)Build a core Query against this table's collection.
reservedProperties()
search($model, $limit, $offset)
select($fields, $filter)
selectFirst($fields, $filter)
selectStatement($fields, $filter)
selectValue($field, $filter)
selectValues($field, $filter)
setEntityClass($class)Use a hand-written entity class for this table's rows instead of a generated one -- the normal case as soon as the entity needs any behaviour of its own.
setName($name)
store($models)Insert or update one or more rows (storeStatement), in a single transaction.
storeStatement($models)Build an upsert: insert the rows, and on a key conflict update their non-key columns instead of failing.
toPHP()
update($values, $filter)Update the rows matching $filter, warning when the statement turns out to change nothing.
updateById($values)Update one row, identified by its primary key -- which must be present in $values and is not itself updated.
updateStatement($values, $filter)
__construct($handler, $name, $register)Constructor

Constants1

ENTITY_NAMESPACE

Namespace the generated entity classes (generateEntityClass) are declared in.

const ENTITY_NAMESPACE = 'MMO\\pdo\\entities'

Properties8

autoId

The name of the primary column carrying AUTO_INCREMENT, or null if there is none.

protected ?string $autoId = null
Type
null | string
NOTE: this used to be typed `bool` while being assigned the column's NAME, which PHP silently coerced to `true` -- so the name (the one thing callers need, to write back the id the database generated on INSERT) was never actually retrievable. Verified directly.

entityClass

protected ?string $entityClass = null
Type
null | string

extra

protected array $extra = []
Type
array

fields

protected array $fields = []
Type
array

handler

#[MMO\core\attributes\Serialize(false)] protected MMO\pdo\interfaces\iHandler $handler
Type
iHandler

ids

protected array $ids = []
Type
array

liaisons

protected array $liaisons = []
Type
array

name

Table name

protected string $name = ''
Type
string

Methods39

count($filter)

Table.php:331
function count(MMO\core\interfaces\iFilter|array|string|null $filter = null): int
$filter = nulliFilter | array | string | null
returnsinthow many rows match $filter.

createStatement($ifNotExists)

Table.php:283

Create a CREATE TABLE query

function createStatement(bool $ifNotExists = false): MMO\pdo\statements\CreateStatement
$ifNotExists = falsebool
returnsCreateStatement

delete($filter, $limit, $allowAll)

Table.php:486

Delete the rows matching $filter.

function delete( MMO\core\interfaces\iFilter|array|string|null $filter = null, ?int $limit = null, bool $allowAll = false ): int
$filter = nulliFilter | array | string | null
$limit = nullnull | int
$allowAll = falsebooldeleting with no filter empties the table, so it has to be asked for explicitly
returnsintthe number of rows deleted
throwsif $filter is empty and $allowAll is false

drop($ifExists)

Table.php:507
function drop(bool $ifExists = true): bool
$ifExists = truebool
returnsbooltrue if the table was actually dropped

dropStatement($ifExists)

Table.php:499
function dropStatement(bool $ifExists = false): MMO\pdo\statements\DropStatement
$ifExists = falsebool
returnsDropStatement

generateEntityClass()

Table.php:152
function generateEntityClass(): stringNOTE: this used to be built from `$handler->getHref()`, i.e. the DSN -- which for SQLite is an absolute filename, so the class was named after wherever the database happened to sit (`sqlite__home_someone_project_data_sqlite_user`). That is machine-specific, and the name ends up in serialized entity references, so it could not survive being moved between machines. It is now derived from the table name plus a digest of its column SHAPE: stable everywhere, and still distinct for two same-named tables whose columns differ.
returnsstringthe fully-qualified name of the PDOEntity subclass generated for this table.

getAutoId()

Table.php:97
function getAutoId(): ?string
returnsnull | stringthe name of the AUTO_INCREMENT primary column, if the table has one.

getEntityClass()

Table.php:166
function getEntityClass(): string
returnsstringthe entity class for this table's rows: the one set with setEntityClass, or a class generated (once) from the columns themselves.

getName($withPrefix)

Table.php:101
function getName(bool $withPrefix = true): string
$withPrefix = truebool
returnsstring

insert($models)

Table.php:371

Insert one or more rows.

function insert(array ...$models): string|false
...$modelsarray
returnsstring | falsethe id the database generated for the LAST row (iHandler::lastId), or false if the table has no AUTO_INCREMENT column

insertStatement($models)

Table.php:356

Build an INSERT for one or more rows.

function insertStatement(array ...$models): MMO\pdo\statements\InsertStatement
...$modelsarray
returnsInsertStatement

query($repo, $filter, $fields, $sort, $limit, $offset)

Table.php:262

Build a core Query against this table's collection.

function query( ?MMO\core\interfaces\iRepository $repo = null, MMO\core\interfaces\iFilter|array|string $filter = [], array|string $fields = [], array|string $sort = [], ?int $limit = null, ?int $offset = null ): MMO\core\entities\QueryWARNING for whoever implements the repository side: a Query's field list is schema-driven, not column-driven, so it asks for properties that are NOT columns of this table -- `status`, `uid` and `metadata` come with every entity, and [`Query::listOnly()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/entities/Query.md#query-listonly) additionally requests `label` and filters on `status`. Whatever turns a Query into SQL must intersect its fields with [`getFields`](https://mcp.mmoframework.fr/documentation/mmo.pdo/php/helpers/Table.md#table-getfields) and decide what to do with the rest, or the database will be asked for columns that do not exist.
$repo = nullnull | iRepository
$filter = []iFilter | array | string
$fields = []array | string
$sort = []array | string
$limit = nullnull | int
$offset = nullnull | int
returnsQuery

reservedProperties()

Table.php:193
protected function reservedProperties(): array
returnsarrayevery property PDOEntity already declares, mapped to whether it is an #[ArrayProperty] (i.e. part of the entity's data) rather than internal bookkeeping.

selectFirst($fields, $filter)

Table.php:313
function selectFirst( array|string|null $fields = null, MMO\core\interfaces\iFilter|array|string|null $filter = null ): array|false
$fields = nullarray | string | null
$filter = nulliFilter | array | string | null
returnsarray | falsethe first matching row, or false if there is none.

selectValue($field, $filter)

Table.php:321
function selectValue( string $field, MMO\core\interfaces\iFilter|array|string|null $filter = null ): mixed
$fieldstring
$filter = nulliFilter | array | string | null
returnsmixedone column of the first matching row (null for a SQL NULL), or false if there is none.
$users->selectValue('email', ['name' => 'ada']); // null if ada has no email, false if there is no ada

selectValues($field, $filter)

Table.php:326
function selectValues( string $field, MMO\core\interfaces\iFilter|array|string|null $filter = null ): array
$fieldstring
$filter = nulliFilter | array | string | null
returnsarrayone column of every matching row.

setEntityClass($class)

Table.php:181

Use a hand-written entity class for this table's rows instead of a generated one -- the normal case as soon as the entity needs any behaviour of its own.

function setEntityClass(string $class): self
$classstringan iEntity implementation (PDOEntity is the intended base)
returnsself
throwsif $class is not an entity

store($models)

Table.php:416

Insert or update one or more rows (storeStatement), in a single transaction.

function store(array ...$models): string|false
...$modelsarray
returnsstring | falseinsert -- but note this is only meaningful when a row was actually INSERTED: after a conflict resolved as an update, the driver still reports the last id it ever generated

storeStatement($models)

Table.php:383

Build an upsert: insert the rows, and on a key conflict update their non-key columns instead of failing.

function storeStatement(array ...$models): MMO\pdo\statements\InsertStatement
...$modelsarray
returnsInsertStatement

toPHP()

Table.php:206
function toPHP(): string
See
getEntityClass which evaluates it
returnsstringthe PHP source of this table's generated entity class, ready for eval().
throwsif a column's name is one the entity base class reserves for its own internals

update($values, $filter)

Table.php:442

Update the rows matching $filter, warning when the statement turns out to change nothing.

function update( array $values, MMO\core\interfaces\iFilter|array|string|null $filter = null ): int
$valuesarray
$filter = nulliFilter | array | string | null
returnsintthe number of rows changed

updateById($values)

Table.php:455

Update one row, identified by its primary key -- which must be present in $values and is not itself updated.

function updateById(array $values): int
$valuesarray
returnsintthe number of rows changed
throwsif a primary key column is missing from $values

updateStatement($values, $filter)

Table.php:432
function updateStatement( array $values, MMO\core\interfaces\iFilter|array|string|null $filter = null ): MMO\pdo\statements\UpdateStatement
$valuesarraycolumn => value (a key may carry a bind type; :raw renders a SQL expression)
$filter = nulliFilter | array | string | null
returnsUpdateStatement

__construct($handler, $name, $register)

Table.php:76

Constructor

function __construct( MMO\pdo\interfaces\iHandler $handler, ?string $name = null, bool $register = true )
$handleriHandler[description]
$name = nullnull | stringused to set manually the table name (in case you use another table definition)
$register = trueboolif true, add the table to the handler