Documentation

Core_DataBase_Mysql extends Core_DataBase
in package

MySQL DataBase driver

Tags
subpackage

Core\Database

version
7.x
author

Hostmake LLC

copyright

© 2005-2024 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru

Table of Contents

Properties

$instance  : mixed
The singleton instances.
$_asObject  : mixed
Get result as object
$_collations  : null|array<string|int, mixed>
Cache for getCollations()
$_colors  : mixed
Colors array
$_columnQuoteCharacter  : mixed
$_config  : mixed
Driver's configuration
$_connection  : mixed
Driver's connection
$_engines  : null|array<string|int, mixed>
Cache for getEngines()
$_lastQuery  : mixed
Last executed query
$_likeReplacements  : array<string|int, mixed>
Array of replacements for LIKE
$_maxObjects  : int
Maximum number of objects Максимальное количество объектов в кэше
$_queryType  : mixed
Type of query: 0 - SELECT 1 - INSERT 2 - UPDATE 3 - DELETE 4 - RENAME 5 - ALTER 6 - DROP 7 - TRUNCATE 8 - OPTIMIZE 9 - SHOW 10 - LOCK 99 - OTHER
$_quoteColumnNameCache  : array<string|int, mixed>
Quoted column name cache
$_result  : resource|null
Result of query
$_separator  : mixed
Array of allowed separators, e.g. table.field => `table`.`field`, a + b => `a` + `b`
$_tableQuoteCharacter  : mixed
$_unbuffered  : mixed
Query without fetching and buffering the result rows
$_words  : mixed
Words array

Methods

__construct()  : mixed
Constructor.
__destruct()  : mixed
Destructor
asAssoc()  : self
Set result type as an array
asObject()  : self
Set result type as an object with className
begin()  : self
Start SQL-transaction
commit()  : self
Commit SQL-transaction
connect()  : bool
Connect to the database
current()  : mixed
Get next row for last query result as an associative array or as an object
disconnect()  : self
Close MySQL connection
dump()  : mixed
Dump table $tableName
dumpStructure()  : mixed
Dump structure of table $tableName
escape()  : string
Escapes special characters in a string for use in an SQL statement
escapeLike()  : string
Escape value in LIKE conditions
free()  : self
Free last result memory
getAffectedRows()  : int|null
Get number of affected rows in previous MySQL operation
getCollations()  : array<string|int, mixed>
Get Collations
getColumnCount()  : int|null
Returns the number of columns in the result set
getColumns()  : array<string|int, mixed>
Get list of columns in the table
getColumnType()  : array<string|int, mixed>
Get extended column type information
getColumnTypeAndLength()  : array<string|int, mixed>
Split column type into type and length
getConfig()  : array<string|int, mixed>
Get current config array (without username and password)
getConnection()  : resource
Get MySQL connection
getEngines()  : array<string|int, mixed>
Get engines
getFullColumns()  : array<string|int, mixed>
Get list of columns in the table
getIndexes()  : array<string|int, mixed>
Get list of indexes in the table
getInsertId()  : int|null
Get the ID generated in the last query
getLastQuery()  : string
Get last query
getNumRows()  : int|null
Get number of rows in result
getProcesslist()  : array<string|int, mixed>
Get the process list indicates the operations currently being performed
getQueryType()  : int
Get type of query
getResult()  : resource
Get last query result as resource
getTables()  : array<string|int, mixed>
Get list of tables in the database
getTablesSchema()  : array<string|int, mixed>
Get tables schema in the database
getVariables()  : array<string|int, mixed>
Get variables
getVersion()  : string|null
Get database version
highlightSql()  : string
Highlight SQL
instance()  : object
Register an existing instance as a singleton.
isConnected()  : bool
Is database connected
query()  : self
Send a MySQL query
quote()  : string
Convert and escape value for SQL query.
quoteColumnName()  : string
Quote column name, e.g. `columnName` for 'columnName', `columnName` AS `columnNameAlias` for array('columnName', 'columnNameAlias')
quoteTableName()  : string
Quote table name, e.g. `tableName` for 'tableName', `tableName` AS `tableNameAlias` for array('tableName', 'tableNameAlias')
result()  : array<string|int, mixed>
Get last query result rows as an array of associative arrays or as an array of objects
rollback()  : self
Rollback SQL-transaction
selectDb()  : self
Select MySQL database
setCharset()  : self
Set the client character set
setConfig()  : self
Set database config
setIsolationLevel()  : self
Set transaction isolation level
setQueryType()  : self
Set type of query
unbuffered()  : self
Query without fetching and buffering the result rows
_addQuoteColumnNameCache()  : self
Insert a quoted column name into cache
_currentAssoc()  : mixed
Get mysql_fetch_assoc() last result
_currentObject()  : mixed
Get mysql_fetch_object() last result
_fetch()  : array<string|int, mixed>
Fetch query result
_free()  : self
Free result memory
_getDriverName()  : srting
Get full driver name

Properties

$instance

The singleton instances.

public static mixed $instance = array()

$_asObject

Get result as object

protected mixed $_asObject = \FALSE

$_collations

Cache for getCollations()

protected null|array<string|int, mixed> $_collations = \NULL

$_colors

Colors array

protected static mixed $_colors = array('orange', 'blue', 'green', 'brown')

$_columnQuoteCharacter

protected mixed $_columnQuoteCharacter = '`'

$_config

Driver's configuration

protected mixed $_config = \NULL

$_connection

Driver's connection

protected mixed $_connection = \NULL

$_engines

Cache for getEngines()

protected null|array<string|int, mixed> $_engines = \NULL

$_lastQuery

Last executed query

protected mixed $_lastQuery = \NULL

$_likeReplacements

Array of replacements for LIKE

protected array<string|int, mixed> $_likeReplacements = array('%' => '\\%', '_' => '\\_', '\\' => '\\\\')

$_maxObjects

Maximum number of objects Максимальное количество объектов в кэше

protected static int $_maxObjects = 256

$_queryType

Type of query: 0 - SELECT 1 - INSERT 2 - UPDATE 3 - DELETE 4 - RENAME 5 - ALTER 6 - DROP 7 - TRUNCATE 8 - OPTIMIZE 9 - SHOW 10 - LOCK 99 - OTHER

protected mixed $_queryType = \NULL

$_quoteColumnNameCache

Quoted column name cache

protected array<string|int, mixed> $_quoteColumnNameCache = array()

$_result

Result of query

protected resource|null $_result = \NULL

$_separator

Array of allowed separators, e.g. table.field => `table`.`field`, a + b => `a` + `b`

protected mixed $_separator = array('.', ' + ', ' - ', ' / ', ' * ')

$_tableQuoteCharacter

protected mixed $_tableQuoteCharacter = '`'

$_unbuffered

Query without fetching and buffering the result rows

protected mixed $_unbuffered = \FALSE

$_words

Words array

protected static mixed $_words = array(array('AND', 'IS', '&&', 'LOG', 'NOT', 'NOW', 'MIN', '!', '\\|\\|', 'OR', 'OCT', 'TAN', 'STD', 'SHA', 'ORD', 'XOR', 'ASC', 'DESC'), array('SELECT', 'UPDATE', 'INSERT', 'DELETE', 'USING', 'LIMIT', 'OFFSET', 'SET'), array('DATE', 'INTO', 'FROM', 'THEN', 'WHEN', 'WHERE', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'INNER JOIN', 'JOIN', 'ELSE', 'ORDER BY', 'GROUP BY', 'HAVING', 'ON'), array('ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_DECRYPT', 'AES_ENCRYPT', '&&', 'ASCII', 'ASIN', 'ATAN2', 'ATAN', 'AVG', 'BETWEEN', 'BIN', 'BINARY', 'BIT_AND', 'BIT_LENGTH', 'BIT_OR', 'BIT_XOR', 'CASE', 'CAST', 'CEIL', 'CEILING', 'CHAR_LENGTH', 'CHAR', 'CHARACTER_LENGTH', 'CHARSET', 'COALESCE', 'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT_WS', 'CONCAT', 'CONNECTION_ID', 'CONV', 'CONVERT_TZ', 'Convert', 'COS', 'COT', 'COUNT', 'COUNT', 'COUNT(DISTINCT)', 'DISTINCT', 'CRC32', 'CURDATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURTIME', 'DATABASE', 'DATE_ADD', 'DATE_FORMAT', 'DATE_SUB', 'DATEDIFF', 'DAY ', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFYEAR', 'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT', 'DIV', 'ELT', 'ENCODE', 'ENCRYPT', '<=>', 'EXP()', 'EXPORT_SET', 'EXTRACT', 'FIELD', 'FIND_IN_SET', 'FLOOR', 'FORMAT', 'SQL_CALC_FOUND_ROWS ', 'FOUND_ROWS', 'STRAIGHT_JOIN', 'FROM_DAYS', 'FROM_UNIXTIME', 'GET_FORMAT', 'GET_LOCK', 'GREATEST', 'GROUP_CONCAT', 'HEX ', 'HOUR', ' IF ', 'IFNULL', ' IN ', 'INET_ATON', 'INET_NTOA', 'INSTR', 'IS_FREE_LOCK', 'IS NOT NULL', 'IS NOT', 'IS NULL', 'IS_USED_LOCK', 'ISNULL', 'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST', '<<', 'LEFT', 'LENGTH', 'LIKE', 'LN', 'LOAD_FILE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATE', 'LOG10', 'LOG2', 'LOWER', 'LPAD', 'LTRIM', 'MAKE_SET', 'MAKEDATE', 'MAKETIME', 'MASTER_POS_WAIT', 'MATCH', 'MAX', 'MD5', 'MICROSECOND', 'MID', 'MINUTE', 'MOD', '%', 'MONTH', 'MONTHNAME', 'NOT BETWEEN', '!=', 'NOT IN', 'NOT LIKE', 'NOT REGEXP', 'NULLIF', 'OCTET_LENGTH', 'OLD_PASSWORD', 'ORD', 'PASSWORD', 'PERIOD_ADD', 'PERIOD_DIFF', 'PI', '\\+', 'POSITION', 'POW', 'POWER', 'PROCEDURE ANALYSE', 'QUARTER', 'QUOTE', 'RADIANS', 'RAND', 'REGEXP', 'RELEASE_LOCK', 'REPEAT', 'REPLACE', 'REVERSE', '>>', 'RIGHT', 'RLIKE', 'ROUND', 'ROW_COUN', 'RPAD', 'RTRIM', 'SCHEMA', 'SEC_TO_TIME', 'SECOND', 'SESSION_USER', 'SHA1', 'SIGN', 'SLEEP', 'SOUNDEX', 'SOUNDS LIKE', 'SPACE', 'SQRT', 'STDDEV_POP', 'STDDEV_SAMP', 'STDDEV', 'STR_TO_DATE', 'SUBDATE', 'SUBSTR', 'SUBSTRING_INDEX', 'SUBSTRING', 'SUBTIME', 'SUM', 'SYSDATE', 'SYSTEM_USER', 'TIME_FORMAT', 'TIME_TO_SEC', 'TIME', 'TIMEDIFF', '\\*', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TO_DAYS', 'TRIM', 'TRUNCATE', 'UCASE', 'UNCOMPRESS', 'UNCOMPRESSED_LENGTH', 'UNHEX', 'UNIX_TIMESTAMP', 'UPPER', 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'UUID', 'VALUES', 'VAR_POP', 'VAR_SAMP', 'VARIANCE', 'VERSION', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'YEAR', 'YEARWEE'))

Methods

__construct()

Constructor.

public __construct(array<string|int, mixed> $config) : mixed
Parameters
$config : array<string|int, mixed>

config

__destruct()

Destructor

public __destruct() : mixed

asAssoc()

Set result type as an array

public asAssoc() : self
Return values
self

asObject()

Set result type as an object with className

public asObject([mixed $className = NULL ]) : self
Parameters
$className : mixed = NULL

Object class name

Return values
self

begin()

Start SQL-transaction

public begin([string $IsolationLevel = NULL ]) : self
Parameters
$IsolationLevel : string = NULL

Transaction isolation level

Return values
self

commit()

Commit SQL-transaction

public commit() : self
Return values
self

connect()

Connect to the database

public connect() : bool
Tags
hostcms-event

Core_DataBase.onBeforeConnect

hostcms-event

Core_DataBase.onAfterConnect

Return values
bool

current()

Get next row for last query result as an associative array or as an object

public current([bool $bCache = TRUE ]) : mixed
Parameters
$bCache : bool = TRUE

use cache

Tags
see
asAssoc()
see
asObject()
see
result()
Return values
mixed

array or object

disconnect()

Close MySQL connection

public disconnect() : self
Return values
self

dump()

Dump table $tableName

public dump(string $tableName, Core_Out $stdOut) : mixed
Parameters
$tableName : string
$stdOut : Core_Out

return Core_DataBase

dumpStructure()

Dump structure of table $tableName

public dumpStructure(string $tableName, Core_Out $stdOut) : mixed
Parameters
$tableName : string
$stdOut : Core_Out

return Core_DataBase

escape()

Escapes special characters in a string for use in an SQL statement

public escape(string $unescapedString) : string
Parameters
$unescapedString : string

The string that is to be escaped

Return values
string

Escaped string

escapeLike()

Escape value in LIKE conditions

public escapeLike(string $value) : string
Parameters
$value : string
Return values
string

free()

Free last result memory

public free() : self
Return values
self

getAffectedRows()

Get number of affected rows in previous MySQL operation

public getAffectedRows() : int|null
Return values
int|null

number of affected rows or NULL

getCollations()

Get Collations

public getCollations() : array<string|int, mixed>
Return values
array<string|int, mixed>

array[Charset] => array of collations

getColumnCount()

Returns the number of columns in the result set

public getColumnCount() : int|null
Return values
int|null

number of columns in the result set

getColumns()

Get list of columns in the table

public getColumns(string $tableName[, mixed $selectionCondition = NULL ]) : array<string|int, mixed>
Parameters
$tableName : string

Table name

$selectionCondition : mixed = NULL

Selection condition

Tags
see
getFullColumns()
Return values
array<string|int, mixed>

getColumnType()

Get extended column type information

public getColumnType(string $columnType) : array<string|int, mixed>
Parameters
$columnType : string

Column type, e.g. 'TINYINT'

Return values
array<string|int, mixed>

array( 'type' => 'fixed' => 'binary' => 'unsigned' => 'zerofill' => 'min' => 'max' => 'max_length' => );

getColumnTypeAndLength()

Split column type into type and length

public getColumnTypeAndLength(string $columnType) : array<string|int, mixed>
Parameters
$columnType : string

column type

Return values
array<string|int, mixed>

0 => type, 1 => length

getConfig()

Get current config array (without username and password)

public getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

getConnection()

Get MySQL connection

public getConnection() : resource
Return values
resource

getEngines()

Get engines

public getEngines() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFullColumns()

Get list of columns in the table

public getFullColumns(string $tableName[, mixed $selectionCondition = NULL ]) : array<string|int, mixed>
Parameters
$tableName : string

Table name

$selectionCondition : mixed = NULL

Selection condition

Return values
array<string|int, mixed>

getIndexes()

Get list of indexes in the table

public getIndexes(string $tableName[, mixed $selectionCondition = NULL ]) : array<string|int, mixed>
Parameters
$tableName : string

Table name

$selectionCondition : mixed = NULL

Selection condition

Return values
array<string|int, mixed>

getInsertId()

Get the ID generated in the last query

public getInsertId() : int|null
Return values
int|null

getLastQuery()

Get last query

public getLastQuery() : string
Return values
string

getNumRows()

Get number of rows in result

public getNumRows() : int|null
Return values
int|null

number of rows or NULL

getProcesslist()

Get the process list indicates the operations currently being performed

public getProcesslist() : array<string|int, mixed>
Return values
array<string|int, mixed>

getQueryType()

Get type of query

public getQueryType() : int
Return values
int

getResult()

Get last query result as resource

public getResult() : resource
Return values
resource

getTables()

Get list of tables in the database

public getTables([mixed $selectionCondition = NULL ]) : array<string|int, mixed>
Parameters
$selectionCondition : mixed = NULL

Selection condition

Return values
array<string|int, mixed>

getTablesSchema()

Get tables schema in the database

public getTablesSchema([mixed $selectionCondition = NULL ]) : array<string|int, mixed>
Parameters
$selectionCondition : mixed = NULL

Selection condition

Return values
array<string|int, mixed>

getVariables()

Get variables

public getVariables([mixed $selectionCondition = NULL ]) : array<string|int, mixed>
Parameters
$selectionCondition : mixed = NULL

Selection condition

Return values
array<string|int, mixed>

getVersion()

Get database version

public getVersion() : string|null
Return values
string|null

highlightSql()

Highlight SQL

public highlightSql(string $sql) : string
Parameters
$sql : string

SQL

Return values
string

SQL

instance()

Register an existing instance as a singleton.

public static instance([string $name = 'default' ]) : object
Parameters
$name : string = 'default'

driver's name

Return values
object

isConnected()

Is database connected

public isConnected() : bool
Return values
bool

query()

Send a MySQL query

public query(string $sql) : self
Parameters
$sql : string

An SQL query. The query string should not end with a semicolon. Data inside the query should be properly escaped.

Tags
hostcms-event

Core_DataBase.onBeforeQuery

hostcms-event

Core_DataBase.onAfterQuery

Return values
self

quote()

Convert and escape value for SQL query.

public quote(mixed $value) : string
Parameters
$value : mixed
Return values
string

quoteColumnName()

Quote column name, e.g. `columnName` for 'columnName', `columnName` AS `columnNameAlias` for array('columnName', 'columnNameAlias')

public quoteColumnName(mixed $columnName) : string
Parameters
$columnName : mixed

string or array

Return values
string

quoteTableName()

Quote table name, e.g. `tableName` for 'tableName', `tableName` AS `tableNameAlias` for array('tableName', 'tableNameAlias')

public quoteTableName(mixed $tableName) : string
Parameters
$tableName : mixed
Return values
string

result()

Get last query result rows as an array of associative arrays or as an array of objects

public result([bool $bCache = TRUE ]) : array<string|int, mixed>
Parameters
$bCache : bool = TRUE

use cache

Tags
see
current()
Return values
array<string|int, mixed>

rollback()

Rollback SQL-transaction

public rollback() : self
Return values
self

selectDb()

Select MySQL database

public selectDb(string $databaseName) : self
Parameters
$databaseName : string

The name of the database that is to be selected.

Tags
hostcms-event

Core_DataBase.onBeforeSelectDb

hostcms-event

Core_DataBase.onAfterSelectDb

Return values
self

setCharset()

Set the client character set

public setCharset(string $charset) : self
Parameters
$charset : string

A valid character set name.

Return values
self

setConfig()

Set database config

public setConfig(array<string|int, mixed> $config) : self
Parameters
$config : array<string|int, mixed>

config

Return values
self

setIsolationLevel()

Set transaction isolation level

public setIsolationLevel(string $IsolationLevel) : self
Parameters
$IsolationLevel : string

Isolation level: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE

Return values
self

setQueryType()

Set type of query

public setQueryType(int $queryType) : self
Parameters
$queryType : int
Return values
self

unbuffered()

Query without fetching and buffering the result rows

public unbuffered(bool $unbuffered) : self
Parameters
$unbuffered : bool
Return values
self

_addQuoteColumnNameCache()

Insert a quoted column name into cache

protected _addQuoteColumnNameCache(string $columnName, string $value) : self
Parameters
$columnName : string

column name

$value : string

quoted column name

Return values
self

_currentAssoc()

Get mysql_fetch_assoc() last result

protected _currentAssoc([ $result = NULL ]) : mixed
Parameters
$result : = NULL

resource

_currentObject()

Get mysql_fetch_object() last result

protected _currentObject([ $result = NULL ][, bool $bCache = TRUE ]) : mixed
Parameters
$result : = NULL

resource

$bCache : bool = TRUE

use cache

_fetch()

Fetch query result

protected _fetch( $result[, bool $bCache = TRUE ]) : array<string|int, mixed>
Parameters
$result :

resource

$bCache : bool = TRUE

use cache

Return values
array<string|int, mixed>

_free()

Free result memory

protected _free(mixed $result) : self
Parameters
$result : mixed
Return values
self

_getDriverName()

Get full driver name

protected static _getDriverName(string $driver) : srting
Parameters
$driver : string

driver name

Return values
srting

        
On this page

Search results