API / Minn\Runtime / WpdbFields

WpdbFields final class

Minn\Runtime\WpdbFields · public/minn/src/Minn/Runtime/WpdbFields.php · 404 lines

The database object's writers and the charset work behind them (probe db-mail-rewrite-doubts): an insert, replace, update or delete prepares one statement holding every value (a null written as NULL in it), and an insert or replace starts with insert_id at 0; the fields are checked against their columns, every field that would not fit named in the error; a table's columns are kept as the server's rows; a table that cannot be read gives the charset failure; text in a charset other than UTF-8, latin1 or binary is converted by the server; and check_safe_collation passes ASCII, the statements that read no rows, latin1 tables and tables whose text columns use only a binary or general UTF-8 collation.

Used by 1

Constants and properties

privateSAFE_COLLATION = '/^utf8(?:mb[34])?_(?:bin|general_ci)$/i'

Public

staticinsert(object $db, mixed $table, mixed $data, mixed $format, mixed $type): int|bool#

Inserts or replaces a row from processed fields (wpdb::_insert_replace_helper): rows written, or false.

staticupdate(object $db, mixed $table, mixed $data, mixed $where, mixed $format, mixed $whereFormat): int|bool#

Updates the rows a where list matches (wpdb::update): rows written, or false.

staticdelete(object $db, mixed $table, mixed $where, mixed $whereFormat): int|bool#

Deletes the rows a where list matches (wpdb::delete): rows deleted, or false.

staticprocess(object $db, mixed $table, mixed $data, mixed $format): array|false#

The fields with their formats, column charsets and lengths, or false: when a column cannot be read, or when a value would not fit unchanged, last_error naming every such field (wpdb::process_fields).

staticcharsets(object $db, mixed $data, mixed $table): array|false#

Each field with its column's charset, or false when the table cannot be read (wpdb::process_field_charsets).

staticlengths(object $db, mixed $data, mixed $table): array|false#

Each field with its column's length, or false when the table cannot be read (wpdb::process_field_lengths).

staticstrip(object $db, mixed $data): mixed#

Each text value cut to what its column keeps (wpdb::strip_invalid_text): malformed bytes dropped for UTF-8, four-byte characters too for utf8, latin1 and binary kept, then cut to the column's length; text in any other charset goes through the server's conversion, in one query.

staticstripQuery(object $db, mixed $query): mixed#

A query with what its table (the connection, when it names none) cannot hold dropped (wpdb::strip_invalid_text_from_query).

staticsafeCollation(object $db, mixed $query): bool#

Whether a query can skip the text check (wpdb::check_safe_collation).

statictableCharset(object $db, mixed $table): mixed#

The charset a table's text columns share, kept for the request (wpdb::get_table_charset); pre_get_table_charset may answer first, and a table the server cannot describe is the charset failure.

staticcolumnCharset(object $db, mixed $table, mixed $column): mixed#

A column's charset: false for one that holds no text, the table's for a column it does not have (wpdb::get_col_charset).

staticcolumnLength(object $db, mixed $table, mixed $column): mixed#

The most a text or binary column holds, false for any other column, the charset failure for a table that cannot be read (wpdb::get_col_length).

staticqueryCharset(object $db, string $query): string|false#

The charset a query's text is held to: its table's, the connection's when it names none or its table cannot be read.

Internals 9

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatecolumns(object $db, mixed $table): array#

A table's columns, the server's SHOW FULL COLUMNS rows by lower-cased name, kept in col_meta; empty for a table the server cannot describe.

@return array<string, object>
privatesharedCharset(array $columns): string|false#

The charset a table's columns come to (probe invalid-text): binary when one holds bytes, false when none holds text, else their one charset; latin1 beside others does not count, utf8 beside utf8mb4 is utf8, and any other mixture is ascii.

$columnsarray<string, object>
privatecharsetOf(object $db, string $table): mixed#

A table's charset through the object's own get_table_charset, which a subclass may answer.

privateunreadable(): mixed#

The table charset failure.

privatecut(string $value, string $charset, mixed $length): string#

A value cut to a column's length: bytes for latin1 (one character each) and the byte types, characters otherwise.

privateconvert(object $db, array $data, array $server): mixed#

Text in charsets PHP does not judge here, converted by the server to the charset and back, cut to each column's length on the way.

$dataarray<array-key, array<string, mixed>>
$serverarray<array-key, array<string, mixed>>
privatemarks(array $fields): array#

The values a field list sends and the placeholder (or NULL) each takes in the statement.

$fieldsarray<array-key, array<string, mixed>>
@return array{0: list<mixed>, 1: list<string>}
privateconditions(array $conditions): array#

A where list as SQL: each field equal to its placeholder, or IS NULL.

$conditionsarray<array-key, array<string, mixed>>
@return array{0: list<mixed>, 1: string}
privatesend(object $db, string $sql, array $values): int|bool#

Sends a writer's one prepared statement, its values already checked.