MySQLDatabase
class MySQLDatabase extends Database implements TransactionManager
MySQL connector class.
Supported indexes for {@link requireTable()}
You are advised to backup your tables if changing settings on an existing database
connection_charset
and charset
should be equal, similarly so should connection_collation
and collation
Traits
Constants
PARTIAL_QUERY |
|
FULL_QUERY |
|
Config options
connection_charset | String | Default connection charset (may be overridden in $databaseConfig) | |
connection_collation | string | Default connection collation | |
charset | string | Default charset | |
collation | string | Default collation |
Methods
Execute the given SQL parameterised query with the specified arguments
Add the sql queries that need to be partially or fully matched
Get the sql queries that need to be partially or fully matched
Get the autogenerated ID from the previous INSERT query.
Determines if we are connected to a server AND have a valid database selected.
Returns an escaped string. This string won't be quoted, so would be suitable for appending to other quoted strings.
Escapes an identifier (table / database name). Typically the value is simply double quoted. Don't pass in already escaped identifiers in, as this will double escape the value!
Clear all data in a given table
Generates a WHERE clause for null comparison check
Generate a WHERE clause for text matching.
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime in a certain format
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime addition
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime substraction
Returns true if this database supports collations
Can the database override timezone as a connection setting, or does it use the system timezone exclusively?
Get the database server type (e.g. mysql, postgresql).
The core search engine, used by this class and its subclasses to do fun stuff.
Determines if this database supports transactions
Does this database support savepoints in transactions By default it is assumed that they don't unless they are explicitly enabled.
Invoke $callback within a transaction
Start a prepared transaction See http://developer.postgresql.org/pgdocs/postgres/sql-set-transaction.html for details on transaction isolation options
Create a savepoint that you can jump back to if you encounter problems
Rollback or revert to a savepoint if your queries encounter problems If you encounter a problem at any point during a transaction, you may need to rollback that particular query, or return to a savepoint
Commit everything inside this transaction so far
Return depth of current transaction
Determines if the used database supports application-level locks, which is different from table- or row-level locking.
Returns if the lock is available.
Sets an application-level lock so that no two processes can run at the same time, also called a "cooperative advisory lock".
Remove an application-level lock file to allow another process to run (if the execution aborts (e.g. due to an error) all locks are automatically released).
Instruct the database to generate a live connection
Determine if the database with the specified name exists
Change the connection to the specified database, optionally creating the database if it doesn't exist in the current schema.
Return SQL expression used to represent the current date/time
Returns the database-specific version of the random() function
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .
Gets the uninherited value for the given config option
Sets the SQL mode
Sets the system timezone for the database connection
Details
in Database at line 67
DBConnector
getConnector()
Get the current connector
in Database at line 77
setConnector(DBConnector $connector)
Injector injection point for connector dependency
in Database at line 94
DBSchemaManager
getSchemaManager()
Returns the current schema manager
in Database at line 104
setSchemaManager(DBSchemaManager $schemaManager)
Injector injection point for schema manager
in Database at line 125
DBQueryBuilder
getQueryBuilder()
Returns the current query builder
in Database at line 135
setQueryBuilder(DBQueryBuilder $queryBuilder)
Injector injection point for schema manager
at line 378
Query
query(string $sql, int $errorLevel = E_USER_ERROR)
Execute the given SQL query.
at line 384
Query
preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)
Execute the given SQL parameterised query with the specified arguments
in Database at line 279
static
setWhitelistQueryArray(array $whitelistArray)
Add the sql queries that need to be partially or fully matched
in Database at line 289
static array
getWhitelistQueryArray()
Get the sql queries that need to be partially or fully matched
in Database at line 300
integer
getGeneratedID(string $table)
Get the autogenerated ID from the previous INSERT query.
in Database at line 311
boolean
isActive()
Determines if we are connected to a server AND have a valid database selected.
in Database at line 323
string
escapeString(mixed $value)
Returns an escaped string. This string won't be quoted, so would be suitable for appending to other quoted strings.
in Database at line 334
string
quoteString(mixed $value)
Wrap a string into DB-specific quotes.
in Database at line 348
string
escapeIdentifier(string|array $value, string $separator = '.')
Escapes an identifier (table / database name). Typically the value is simply double quoted. Don't pass in already escaped identifiers in, as this will double escape the value!
in Database at line 388
manipulate(array $manipulation)
Execute a complex manipulation on the database.
A manipulation is an array of insert / or update sequences. The keys of the array are table names, and the values are map containing 'command' and 'fields'. Command should be 'insert' or 'update', and fields should be a map of field names to field values, NOT including quotes.
The field values could also be in paramaterised format, such as array('MAX(?,?)' => array(42, 69)), allowing the use of raw SQL values such as array('NOW()' => array()).
in Database at line 445
quiet()
Enable supression of database messages.
in Database at line 453
clearAllData()
Clear all data out of the database
at line 533
clearTable(string $table)
Clear all data in a given table
in Database at line 478
string
nullCheckClause(string $field, bool $isNull)
Generates a WHERE clause for null comparison check
at line 406
String
comparisonClause(String $field, String $value, boolean $exact = false, boolean $negate = false, boolean $caseSensitive = null, boolean $parameterised = false)
Generate a WHERE clause for text matching.
at line 430
string
formattedDatetimeClause(string $date, string $format)
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime in a certain format
at line 452
string
datetimeIntervalClause($date, $interval)
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime addition
at line 465
string
datetimeDifferenceClause($date1, $date2)
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime substraction
in Database at line 566
string
concatOperator()
String operator for concatenation of strings
at line 129
boolean
supportsCollations()
Returns true if this database supports collations
at line 134
Boolean
supportsTimezoneOverride()
Can the database override timezone as a connection setting, or does it use the system timezone exclusively?
in Database at line 591
string
getVersion()
Query for the version of the currently connected database
at line 139
string
getDatabaseServer()
Get the database server type (e.g. mysql, postgresql).
This value is passed to the connector as the 'driver' argument when initiating a database connection
in Database at line 609
int
affectedRows()
Return the number of rows affected by the previous operation.
at line 160
PaginatedList
searchEngine(array $classesToSearch, string $keywords, integer $start, integer $pageLength, string $sortBy = "Relevance DESC", string $extraFilter = "", boolean $booleanSearch = false, string $alternativeFileFilter = "", boolean $invertedMatch = false)
The core search engine, used by this class and its subclasses to do fun stuff.
Searches both SiteTree and File.
at line 323
boolean
supportsTransactions()
Determines if this database supports transactions
at line 327
boolean
supportsSavepoints()
Does this database support savepoints in transactions By default it is assumed that they don't unless they are explicitly enabled.
in Database at line 669
withTransaction(callable $callback, callable $errorCallback = null, bool|string $transactionMode = false, bool $errorIfTransactionsUnsupported = false)
Invoke $callback within a transaction
in Database at line 707
supportsExtensions($extensions)
at line 332
transactionStart(string|boolean $transactionMode = false, string|boolean $sessionCharacteristics = false)
Start a prepared transaction See http://developer.postgresql.org/pgdocs/postgres/sql-set-transaction.html for details on transaction isolation options
at line 337
transactionSavepoint(string $savepoint)
Create a savepoint that you can jump back to if you encounter problems
at line 342
bool|null
transactionRollback(string|boolean $savepoint = false)
Rollback or revert to a savepoint if your queries encounter problems If you encounter a problem at any point during a transaction, you may need to rollback that particular query, or return to a savepoint
at line 352
bool|null
transactionEnd(bool $chain = false)
Commit everything inside this transaction so far
at line 347
int
transactionDepth()
Return depth of current transaction
at line 483
bool
supportsLocks()
Determines if the used database supports application-level locks, which is different from table- or row-level locking.
See {@link getLock()} for details.
at line 488
bool
canLock(string $name)
Returns if the lock is available.
See {@link supportsLocks()} to check if locking is generally supported.
at line 494
bool
getLock(string $name, integer $timeout = 5)
Sets an application-level lock so that no two processes can run at the same time, also called a "cooperative advisory lock".
Return FALSE if acquiring the lock fails; otherwise return TRUE, if lock was acquired successfully. Lock is automatically released if connection to the database is broken (either normally or abnormally), making it less prone to deadlocks than session- or file-based locks. Should be accompanied by a {@link releaseLock()} call after the logic requiring the lock has completed. Can be called multiple times, in which case locks "stack" (PostgreSQL, SQL Server), or auto-releases the previous lock (MySQL).
Note that this might trigger the database to wait for the lock to be released, delaying further execution.
at line 504
bool
releaseLock(string $name)
Remove an application-level lock file to allow another process to run (if the execution aborts (e.g. due to an error) all locks are automatically released).
at line 68
connect(array $parameters)
Instruct the database to generate a live connection
in Database at line 858
bool
databaseExists(string $name)
Determine if the database with the specified name exists
in Database at line 868
array
databaseList()
Retrieves the list of all databases the user has access to
in Database at line 885
bool
selectDatabase(string $name, bool $create = false, int|bool $errorLevel = E_USER_ERROR)
Change the connection to the specified database, optionally creating the database if it doesn't exist in the current schema.
in Database at line 911
dropSelectedDatabase()
Drop the database that this object is currently connected to.
Use with caution.
in Database at line 925
string|null
getSelectedDatabase()
Returns the name of the currently selected database
at line 517
string
now()
Return SQL expression used to represent the current date/time
at line 523
string
random()
Returns the database-specific version of the random() function
in Configurable at line 20
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .
....).
in Configurable at line 32
mixed
stat(string $name)
deprecated
deprecated 5.0 Use ->config()->get() instead
Get inherited config value
in Configurable at line 44
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
in Configurable at line 57
$this
set_stat(string $name, mixed $value)
deprecated
deprecated 5.0 Use ->config()->set() instead
Update the config value for a given property
at line 108
setSQLMode(string $mode)
Sets the SQL mode
at line 121
selectTimezone(string $timezone)
Sets the system timezone for the database connection