Oihana Php Mysql

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
author

Marc Alcaraz (ekameleon)

since
1.0.0

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

Methods

initializeMysqlRoot()

Initialize the Mysql model reference.

public initializeMysqlRoot([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Tags
throws
DependencyException
NotFoundException
Return values
static

assertHost()

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
throws
InvalidArgumentException

If the host string contains disallowed characters.

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.

Tags
throws
InvalidArgumentException

If the identifier contains invalid characters.

On this page

Search results