Db final class
Minn\Db · public/minn/src/Minn/Db.php · 370 lines
The one door to the database. Every query is a prepared statement; the placeholder types are derived from the PHP values, so callers pass plain arrays and never spell out "issd". A parameter that is a list stands for a list of values: its "?" becomes as many placeholders as the list is long, so "post_type IN (?)" takes the types themselves.
Used by 76 (show)
Constants and properties
| const | INCOMPATIBLE_MODES = array ( 0 => 'NO_ZERO_DATE', 1 => 'ONLY_FULL_GROUP_BY', 2 => 'STRICT_TRANS_TABLES', 3 => 'STRICT_ALL_TABLES', 4 => 'TRADITIONAL', 5 => 'ANSI', ) | The SQL modes WordPress turns off for its session (wpdb's incompatible modes): strictness and the modes that change what queries mean. |
| private | static ?self $shared | |
| private | bool $inTransaction | Whether a transaction this door opened is still open, so a nested call joins it instead of starting another. |
| private | readonly mysqli $connection | Promoted from the constructor. |
| private | readonly string $prefix | Promoted from the constructor. |
| private | static array $writeListeners | |
| private | static ?Closure $optionSource |
Public
| new | __construct(mysqli $connection, string $prefix)# | ||||
| static | columnLength(string $type): array|false# | The most a column of a MySQL type holds, as wpdb::get_col_length answers: characters for char and varchar, bytes for the binary, blob and text types; false for any other type. @return array{type: string, length: int}|false | |||
| static | current(): self# | The connection the request being answered speaks through: its runtime's own, so nothing deep in a render can reach a connection belonging to another request. With no runtime (the command line, the unit suite) it is the process's own connection. This is the one place in the core that asks the runtime anything; the alternative is a database door threaded through every renderer, and the seam is here until that threading is done. | |||
| static | shared(): self# | The one connection for this process, opened from wp-config's constants on first use, its session without the incompatible modes, as WordPress's own connection is (a plugin's insert that leaves out a text column then succeeds, as it does there). | |||
| static | sessionModes(string $modes): string# | The session's modes: the server's, less the reference's incompatible ones and NO_BACKSLASH_ESCAPES, which the engine's own literal escaping (Query\Sql) relies on being off. Plugins see only the reference's list (incompatible_sql_modes). | |||
| static | compatibleModes(string $modes, array $incompatible): string# | A comma-separated SQL mode list without the incompatible ones (any case).
| |||
| method | setModes(string $modes): void# | Sets this session's SQL modes, never NO_BACKSLASH_ESCAPES: the engine's literals escape quotes with a backslash (Query\Sql), which that mode would turn into a plain character, so a set_sql_mode() asking for it gets every other mode it named. | |||
| method | connection(): mysqli# | The underlying mysqli handle, for the facade's wpdb. | |||
| method | escape(string $value): string# | A value escaped for direct interpolation into SQL, for callers that build their own statements. | |||
| method | prefix(): string# | The table prefix from wp-config. | |||
| method | table(string $name): string# | `posts` becomes `wp_posts`; the prefix comes from wp-config.php. | |||
| method | rows(string $sql, array $params = array ( )): array# | Every row of a prepared query, as associative arrays. @return list<array<string, mixed>> | |||
| method | row(string $sql, array $params = array ( )): ?array# | The first row of a prepared query, or null. @return array<string, mixed>|null | |||
| method | value(string $sql, array $params = array ( )): string|int|float|null# | The first column of the first row, or null when there is no row. | |||
| method | execute(string $sql, array $params = array ( )): int# | Runs a write and returns the affected row count. | |||
| static | onWrite(string $table, Closure $listener): void# | Asks to be told whenever a write statement names a table (Content\RowCache drops what it kept from it). | |||
| static | wrote(string $sql): void# | Tells the listeners of every table a write statement names, whichever door ran it (this one, or the facade's wpdb for plugin code). A name that merely contains another (wp_postmeta for posts) is not it. | |||
| static | expand(string $sql, array $params): array# | Rewrites every "?" whose parameter is a list into that many placeholders, and flattens the values to match, so "IN (?)" becomes "IN (?, ?, ?)". An empty list becomes NULL, which nothing is IN, so a caller that means "everything" when the list is empty says so itself.
@return array{0: string, 1: list<mixed>} | |||
| method | transaction(callable $work): mixed# | Runs a unit of work as one transaction: everything the closure writes lands, or none of it does. The closure's return value is passed back. A transaction already open is joined rather than nested, since the storage engine has no nested transactions; the outermost call is the one that commits. A table that cannot do transactions (MyISAM, which no WordPress core table uses) silently keeps each write, which is the behaviour there was before this existed.
| |||
| method | insertId(): int# | The id the last INSERT produced. | |||
| method | option(string $name): ?string# | One option's stored value, or null when it is unset; home and siteurl answer to WP_HOME and WP_SITEURL. Once the runtime boots, the read is its option store's (the autoloaded list, wp_cache's options group), so the engine's own reads cost no query each, as get_option()'s don't. | |||
| static | readOptionsThrough(?Closure $source): void# | Where option reads come from from now on: the runtime's option store, or null for the row itself. | |||
| static | configured(string $name): ?string# | What wp-config.php sets for an option, or null: WP_HOME and WP_SITEURL, when defined, stand for home and siteurl on every read, as on the reference (_config_wp_home), without a trailing slash. | |||
| method | storedOption(string $name): ?string# | One option's row as stored, whatever wp-config.php says, or null when it is unset. |
Internals 2
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
Nothing matches.