Mysql
extends Driver
in package
uses
SqlDialectTrait
MySQL Driver
Table of Contents
Constants
- MAX_ALIAS_LENGTH = 256
- RETRY_ERROR_CODES = []
- SERVER_TYPE_MARIADB = 'mariadb'
- Server type MariaDB
- SERVER_TYPE_MYSQL = 'mysql'
- Server type MySQL
Properties
- $_autoQuoting : bool
- Indicates whether the driver is doing automatic identifier quoting for all queries
- $_baseConfig : array<string, mixed>
- Base configuration settings for MySQL driver
- $_config : array<string, mixed>
- Configuration data.
- $_connection : PDO
- Instance of PDO.
- $_endQuote : string
- String used to end a database identifier quoting to make it safe
- $_schemaDialect : MysqlSchemaDialect|null
- The schema dialect for this driver
- $_startQuote : string
- String used to start a database identifier quoting to make it safe
- $_version : string|null
- The server version
- $connectRetries : int
- The last number of connection retry attempts.
- $featureVersions : array<string, array<string, string>>
- Mapping of feature to db server version for feature availability checks.
- $serverType : string
- Server type.
Methods
- __construct() : mixed
- Constructor
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __destruct() : mixed
- Destructor
- beginTransaction() : bool
- Starts a transaction.
- commitTransaction() : bool
- Commits a transaction.
- compileQuery() : array<string|int, mixed>
- Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
- connect() : bool
- Establishes a connection to the database server
- disableAutoQuoting() : $this
- Disable auto quoting of identifiers in queries.
- disableForeignKeySQL() : string
- Get the SQL for disabling foreign keys.
- disconnect() : void
- Disconnects from database server.
- enableAutoQuoting() : $this
- Sets whether this driver should automatically quote identifiers in queries.
- enabled() : bool
- Returns whether php is able to use this driver for connecting to database
- enableForeignKeySQL() : string
- Get the SQL for enabling foreign keys.
- getConnection() : PDO
- Get the internal PDO connection instance.
- getConnectRetries() : int
- Returns the number of connection retry attempts made.
- getMaxAliasLength() : int|null
- Returns the maximum alias length allowed.
- inTransaction() : bool
- Returns whether a transaction is active for connection.
- isAutoQuotingEnabled() : bool
- Returns whether this driver should automatically quote identifiers in queries.
- isConnected() : bool
- Checks whether the driver is connected.
- isMariadb() : bool
- Returns true if the connected server is MariaDB.
- lastInsertId() : string|int
- Returns last id generated for a table or sequence in database.
- newCompiler() : QueryCompiler
- Returns an instance of a QueryCompiler.
- newTableSchema() : TableSchema
- Constructs new TableSchema.
- prepare() : StatementInterface
- Prepares a sql statement to be executed
- queryTranslator() : Closure
- Returns a callable function that will be used to transform a passed Query object.
- quote() : string
- Returns a value in a safe representation to be used in a query string
- quoteIdentifier() : string
- Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
- rollbackTransaction() : bool
- Rollbacks a transaction.
- schema() : string
- Returns the schema name that's being used.
- schemaDialect() : SchemaDialect
- Get the schema dialect.
- schemaValue() : string
- Escapes values for use in schema definitions.
- setConnection() : $this
- Set the internal PDO connection instance.
- supports() : bool
- Returns whether the driver supports the feature.
- supportsCTEs() : bool
- Returns true if the server supports common table expressions.
- supportsDynamicConstraints() : bool
- Returns whether the driver supports adding or dropping constraints to already created tables.
- supportsNativeJson() : bool
- Returns true if the server supports native JSON columns
- supportsQuoting() : bool
- Checks if the driver supports quoting, as PDO_ODBC does not support it.
- supportsSavePoints() : bool
- Returns whether this driver supports save points for nested transactions.
- supportsWindowFunctions() : bool
- Returns true if the connected server supports window functions.
- version() : string
- Returns connected server version.
- _connect() : bool
- Establishes a connection to the database server
Constants
MAX_ALIAS_LENGTH
protected
int|null
MAX_ALIAS_LENGTH
= 256
Maximum alias length or null if no limit
Tags
RETRY_ERROR_CODES
protected
array<string|int, int>
RETRY_ERROR_CODES
= []
DB-specific error codes that allow connect retry
SERVER_TYPE_MARIADB
Server type MariaDB
protected
string
SERVER_TYPE_MARIADB
= 'mariadb'
SERVER_TYPE_MYSQL
Server type MySQL
protected
string
SERVER_TYPE_MYSQL
= 'mysql'
Properties
$_autoQuoting
Indicates whether the driver is doing automatic identifier quoting for all queries
protected
bool
$_autoQuoting
= false
$_baseConfig
Base configuration settings for MySQL driver
protected
array<string, mixed>
$_baseConfig
= ['persistent' => true, 'host' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'cake', 'port' => '3306', 'flags' => [], 'encoding' => 'utf8mb4', 'timezone' => null, 'init' => []]
$_config
Configuration data.
protected
array<string, mixed>
$_config
$_connection
Instance of PDO.
protected
PDO
$_connection
$_endQuote
String used to end a database identifier quoting to make it safe
protected
string
$_endQuote
= '`'
$_schemaDialect
The schema dialect for this driver
protected
MysqlSchemaDialect|null
$_schemaDialect
$_startQuote
String used to start a database identifier quoting to make it safe
protected
string
$_startQuote
= '`'
$_version
The server version
protected
string|null
$_version
$connectRetries
The last number of connection retry attempts.
protected
int
$connectRetries
= 0
$featureVersions
Mapping of feature to db server version for feature availability checks.
protected
array<string, array<string, string>>
$featureVersions
= ['mysql' => ['json' => '5.7.0', 'cte' => '8.0.0', 'window' => '8.0.0'], 'mariadb' => ['json' => '10.2.7', 'cte' => '10.2.1', 'window' => '10.2.0']]
$serverType
Server type.
protected
string
$serverType
= self::SERVER_TYPE_MYSQL
If the underlying server is MariaDB, its value will get set to 'mariadb'
after version()
method is called.
Methods
__construct()
Constructor
public
__construct([array<string, mixed> $config = [] ]) : mixed
Parameters
- $config : array<string, mixed> = []
-
The configuration for the driver.
Tags
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__destruct()
Destructor
public
__destruct() : mixed
beginTransaction()
Starts a transaction.
public
beginTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
commitTransaction()
Commits a transaction.
public
commitTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
compileQuery()
Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
public
compileQuery(Query $query, ValueBinder $binder) : array<string|int, mixed>
Parameters
- $query : Query
-
The query to compile.
- $binder : ValueBinder
-
The value binder to use.
Tags
Return values
array<string|int, mixed> —containing 2 entries. The first entity is the transformed query and the second one the compiled SQL.
connect()
Establishes a connection to the database server
public
connect() : bool
Return values
bool —true on success
disableAutoQuoting()
Disable auto quoting of identifiers in queries.
public
disableAutoQuoting() : $this
Tags
Return values
$thisdisableForeignKeySQL()
Get the SQL for disabling foreign keys.
public
disableForeignKeySQL() : string
Tags
Return values
stringdisconnect()
Disconnects from database server.
public
disconnect() : void
Tags
enableAutoQuoting()
Sets whether this driver should automatically quote identifiers in queries.
public
enableAutoQuoting([bool $enable = true ]) : $this
Parameters
- $enable : bool = true
-
Whether to enable auto quoting
Tags
Return values
$thisenabled()
Returns whether php is able to use this driver for connecting to database
public
enabled() : bool
Return values
bool —true if it is valid to use this driver
enableForeignKeySQL()
Get the SQL for enabling foreign keys.
public
enableForeignKeySQL() : string
Tags
Return values
stringgetConnection()
Get the internal PDO connection instance.
public
getConnection() : PDO
Return values
PDOgetConnectRetries()
Returns the number of connection retry attempts made.
public
getConnectRetries() : int
Return values
intgetMaxAliasLength()
Returns the maximum alias length allowed.
public
getMaxAliasLength() : int|null
This can be different from the maximum identifier length for columns.
Return values
int|null —Maximum alias length or null if no limit
inTransaction()
Returns whether a transaction is active for connection.
public
inTransaction() : bool
Return values
boolisAutoQuotingEnabled()
Returns whether this driver should automatically quote identifiers in queries.
public
isAutoQuotingEnabled() : bool
Tags
Return values
boolisConnected()
Checks whether the driver is connected.
public
isConnected() : bool
Tags
Return values
boolisMariadb()
Returns true if the connected server is MariaDB.
public
isMariadb() : bool
Return values
boollastInsertId()
Returns last id generated for a table or sequence in database.
public
lastInsertId([string|null $table = null ][, string|null $column = null ]) : string|int
Parameters
- $table : string|null = null
-
table name or sequence to get last insert value from.
- $column : string|null = null
-
the name of the column representing the primary key.
Tags
Return values
string|intnewCompiler()
Returns an instance of a QueryCompiler.
public
newCompiler() : QueryCompiler
Tags
Return values
QueryCompilernewTableSchema()
Constructs new TableSchema.
public
newTableSchema(string $table[, array<string|int, mixed> $columns = [] ]) : TableSchema
Parameters
- $table : string
-
The table name.
- $columns : array<string|int, mixed> = []
-
The list of columns for the schema.
Tags
Return values
TableSchemaprepare()
Prepares a sql statement to be executed
public
prepare(Query|string $query) : StatementInterface
Parameters
- $query : Query|string
-
The query to prepare.
Return values
StatementInterfacequeryTranslator()
Returns a callable function that will be used to transform a passed Query object.
public
abstract queryTranslator(string $type) : Closure
Parameters
- $type : string
-
The type of query to be transformed (select, insert, update, delete).
Tags
Return values
Closurequote()
Returns a value in a safe representation to be used in a query string
public
quote(mixed $value[, mixed $type = PDO::PARAM_STR ]) : string
Parameters
- $value : mixed
-
The value to quote.
- $type : mixed = PDO::PARAM_STR
-
Must be one of the \PDO::PARAM_* constants
Tags
Return values
stringquoteIdentifier()
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
public
abstract quoteIdentifier(string $identifier) : string
Parameters
- $identifier : string
-
The identifier expression to quote.
Tags
Return values
stringrollbackTransaction()
Rollbacks a transaction.
public
rollbackTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
schema()
Returns the schema name that's being used.
public
schema() : string
Tags
Return values
stringschemaDialect()
Get the schema dialect.
public
schemaDialect() : SchemaDialect
Tags
Return values
SchemaDialectschemaValue()
Escapes values for use in schema definitions.
public
schemaValue(mixed $value) : string
Parameters
- $value : mixed
-
The value to escape.
Tags
Return values
string —String for use in schema definitions.
setConnection()
Set the internal PDO connection instance.
public
setConnection(PDO $connection) : $this
Parameters
- $connection : PDO
-
PDO instance.
Tags
Return values
$thissupports()
Returns whether the driver supports the feature.
public
supports(string $feature) : bool
Parameters
- $feature : string
-
Driver feature name
Tags
Return values
boolsupportsCTEs()
Returns true if the server supports common table expressions.
public
supportsCTEs() : bool
Use supports(DriverInterface::FEATURE_CTE)
instead
Return values
boolsupportsDynamicConstraints()
Returns whether the driver supports adding or dropping constraints to already created tables.
public
supportsDynamicConstraints() : bool
Tags
Return values
bool —True if driver supports dynamic constraints.
supportsNativeJson()
Returns true if the server supports native JSON columns
public
supportsNativeJson() : bool
Use supports(DriverInterface::FEATURE_JSON)
instead
Return values
boolsupportsQuoting()
Checks if the driver supports quoting, as PDO_ODBC does not support it.
public
supportsQuoting() : bool
Use supports(DriverInterface::FEATURE_QUOTE)
instead
Return values
boolsupportsSavePoints()
Returns whether this driver supports save points for nested transactions.
public
supportsSavePoints() : bool
Tags
Return values
bool —True if save points are supported, false otherwise.
supportsWindowFunctions()
Returns true if the connected server supports window functions.
public
supportsWindowFunctions() : bool
Use supports(DriverInterface::FEATURE_WINDOW)
instead
Return values
boolversion()
Returns connected server version.
public
version() : string
Return values
string_connect()
Establishes a connection to the database server
protected
_connect(string $dsn, array<string, mixed> $config) : bool
Parameters
- $dsn : string
-
A Driver-specific PDO-DSN
- $config : array<string, mixed>
-
configuration to be used for creating connection
Return values
bool —true on success