MysqlAssertionsTrait
Provides assertion methods to validate MySQL-related identifiers and hostnames.
Ensures that database names, table names, user names, and host strings conform to expected syntax constraints before they are used in queries.
Intended to be reused across traits or models that manage MySQL operations.
Tags
Table of Contents
Methods
- assertHost() : void
- Validates a MySQL host string.
- assertIdentifier() : void
- Validates a MySQL identifier such as a database name, user name, or table name.
Methods
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
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.