MysqlRootTrait uses \oihana\traits\ContainerTrait, trait:short, \oihana\models\pdo\PDOTrait
Provides support for accessing and initializing a root-level MySQL administrative model, typically used to perform high-privilege operations via a separate `MysqlModel` instance.
This trait depends on a PSR-11 compatible container and expects a MysqlModel instance
to be provided directly or by reference (as a container service name).
Tags
Table of Contents
Properties
- $mysqlRoot : MysqlModel|null
- The mysql root model reference.
Methods
- initializeMysqlRoot() : static
- Initialize the Mysql model reference.
- assertHost() : void
- Validates a MySQL host string.
- assertIdentifier() : void
- Validates a MySQL identifier such as a database name, user name, or table name.
Properties
$mysqlRoot
The mysql root model reference.
public
MysqlModel|null
$mysqlRoot
= null
Methods
initializeMysqlRoot()
Initialize the Mysql model reference.
public
initializeMysqlRoot([array<string|int, mixed> $init = [] ]) : static
Parameters
- $init : array<string|int, mixed> = []
Tags
Return values
staticassertHost()
Validates a MySQL host string.
protected
assertHost(string $host) : void
A valid host string may contain:
- letters (a–z, A–Z)
- digits (0–9)
- dots (.)
- hyphens (-)
- underscores (_) and percent signs (%) for wildcards
Parameters
- $host : string
-
The host name or IP to validate (e.g., 'localhost', '127.0.0.1', '%.example.com').
Tags
assertIdentifier()
Validates a MySQL identifier such as a database name, user name, or table name.
protected
assertIdentifier(string $name) : void
A valid identifier consists of letters (a–z, A–Z), digits (0–9), and underscores (_). This ensures safe usage in SQL queries without risk of injection or syntax errors.
Parameters
- $name : string
-
The identifier to validate.