eZPublish  4.4
eZMySQLDB Class Reference

The eZMySQLDB class provides MySQL implementation of the database interface. More...

+ Inheritance diagram for eZMySQLDB:
+ Collaboration diagram for eZMySQLDB:

Public Member Functions

 arrayQuery ($sql, $params=array(), $server=false)
 
 availableDatabases ()
 
 beginQuery ()
 
 bindingType ()
 
 bindVariable ($value, $fieldDef=false)
 
 bitAnd ($arg1, $arg2)
 
 bitOr ($arg1, $arg2)
 
 checkCharset ($charset, &$currentCharset)
 
 close ()
 
 commitQuery ()
 
 concatString ($strings=array())
 
 createDatabase ($dbName)
 
 databaseClientVersion ()
 
 databaseName ()
 
 databaseServerVersion ()
 
 dropTempTable ($dropTableQuery= '', $server=self::SERVER_SLAVE)
 
 escapeString ($str)
 
 eZMySQLDB ($parameters)
 
 eZTableList ($server=eZDBInterface::SERVER_MASTER)
 
 isCharsetSupported ($charset)
 
 lastSerialID ($table=false, $column=false)
 
 lock ($table)
 
 md5 ($str)
 
 query ($sql, $server=false)
 
 relationCount ($relationType=eZDBInterface::RELATION_TABLE)
 
 relationCounts ($relationMask)
 
 relationList ($relationType=eZDBInterface::RELATION_TABLE)
 
 relationMatchRegexp ($relationType)
 
 relationName ($relationType)
 Local eZDBInterface::relationName() override to support the foreign keys type relation. More...
 
 removeDatabase ($dbName)
 
 removeRelation ($relationName, $relationType)
 
 rollbackQuery ()
 
 setError ()
 
 subString ($string, $from, $len=null)
 
 supportedRelationTypeMask ()
 
 supportedRelationTypes ()
 
 supportsDefaultValuesInsertion ()
 
 unlock ()
 
- Public Member Functions inherited from eZDBInterface
 attribute ($name)
 
 attributes ()
 
 availableDatabases ()
 
 begin ()
 
 beginQuery ()
 
 charset ()
 
 checkCharset ($charset, &$currentCharset)
 
 commit ()
 
 commitQuery ()
 
 connectRetryCount ()
 
 connectRetryWaitTime ()
 
 createTempTable ($createTableQuery= '', $server=self::SERVER_SLAVE)
 
 databaseServerVersion ()
 
 dropTempTable ($dropTableQuery= '', $server=self::SERVER_SLAVE)
 
 dropTempTableList ($tableList, $server=self::SERVER_SLAVE)
 
 errorMessage ()
 
 errorNumber ()
 
 eZDBInterface ($parameters)
 
 generateFailedTransactionStack ()
 
 generateSQLINStatement ($elements, $columnName= '', $not=false, $unique=true, $type=false)
 This function can be used to create a SQL IN statement to be used in a WHERE clause: More...
 
 generateUniqueTempTableName ($pattern, $randomizeIndex=false, $server=self::SERVER_SLAVE)
 
 hasAttribute ($name)
 
 hasRequiredServerVersion ($minVersion, $name=false)
 
 implodeWithTypeCast ($glue, &$pieces, $type)
 
 insertFile ($path, $sqlFile, $usePathType=true)
 
 invalidateTransaction ()
 
 isCharsetSupported ($charset)
 
 isTransactionValid ()
 
 rollback ()
 
 rollbackQuery ()
 
 setIsSQLOutputEnabled ($enabled)
 
 socketPath ()
 
 supportsDefaultValuesInsertion ()
 
 transactionCounter ()
 
 usesBuiltinEncoding ()
 
 useShortNames ()
 
 version ()
 

Public Attributes

 $TempTableList
 
const RELATION_FOREIGN_KEY = 5
 
const RELATION_FOREIGN_KEY_BIT = 32
 
- Public Attributes inherited from eZDBInterface
 $Charset
 The charset used for the current database. More...
 
 $ConnectRetries
 The number of times to retry a connection if it fails. More...
 
 $DB
 The current database name. More...
 
 $DBConnection
 The current connection, false if not connection has been made. More...
 
 $DBWriteConnection
 Contains the write database connection if used. More...
 
 $EndTime
 The end time of the tiemr. More...
 
 $ErrorMessage
 The database error message of the last executed function. More...
 
 $ErrorNumber = 0
 The database error message number of the last executed function. More...
 
 $InputTextCodec
 
 $IsConnected = false
 Contains true if we're connected to the database backend. More...
 
 $NumQueries = 0
 Contains number of queries sended to DB. More...
 
 $OutputSQL
 Setting if SQL queries should be sent to debug output. More...
 
 $OutputTextCodec
 Instance of a textcodec which handles text conversion, may not be set if no builtin encoding is used. More...
 
 $Password
 Stores the database connection password. More...
 
 $Port
 Contains the current port. More...
 
 $RecordError = true
 If true then ErrorMessage and ErrorNumber get filled. More...
 
 $Server
 Contains the current server. More...
 
 $SlaveDB
 The slave database name. More...
 
 $SlavePassword
 The slave database user password. More...
 
 $SlavePort
 The slave server port. More...
 
 $SlaveServer
 The slave server name. More...
 
 $SlaveUser
 The slave database user. More...
 
 $SocketPath
 The socket path, used by MySQL. More...
 
 $StartTime
 The start time of the timer. More...
 
 $TimeTaken
 The total number of milliseconds the timer took. More...
 
 $TransactionCounter
 The transaction counter, 0 means no transaction. More...
 
 $TransactionIsValid
 Flag which tells if a transaction is considered valid or not A transaction will be made invalid if SQL errors occur. More...
 
 $UseBuiltinEncoding
 True if a builtin encoder is to be used, this means that all input/output text is converted. More...
 
 $UsePersistentConnection = false
 If true then the database connection should be persistent. More...
 
 $User
 Stores the database connection user. More...
 
 $UserSlaveServer
 Contains true if slave servers are enabled. More...
 
const BINDING_NAME = 1
 
const BINDING_NO = 0
 
const BINDING_ORDERED = 2
 
const ERROR_MISSING_EXTENSION = 1
 
const RELATION_INDEX = 4
 
const RELATION_INDEX_BIT = 16
 
const RELATION_MASK = 31
 
const RELATION_NONE = 0
 
const RELATION_SEQUENCE = 1
 
const RELATION_SEQUENCE_BIT = 2
 
const RELATION_TABLE = 0
 
const RELATION_TABLE_BIT = 1
 
const RELATION_TRIGGER = 2
 
const RELATION_TRIGGER_BIT = 4
 
const RELATION_VIEW = 3
 
const RELATION_VIEW_BIT = 8
 
const SERVER_MASTER = 1
 
const SERVER_SLAVE = 2
 

Private Member Functions

 checkCharsetPriv ($charset, &$currentCharset)
 
 connect ($server, $db, $user, $password, $socketPath, $charset=null, $port=false)
 

Additional Inherited Members

- Protected Member Functions inherited from eZDBInterface
 isConnected ()
 
 relationName ($relationType)
 
 reportError ()
 

Detailed Description

The eZMySQLDB class provides MySQL implementation of the database interface.

eZMySQLDB is the MySQL implementation of eZDB.

See Also
eZDB

Member Function Documentation

eZMySQLDB::arrayQuery (   $sql,
  $params = array(),
  $server = false 
)
virtual

Executes an SQL query and returns the result as an array of accociative arrays.

Parameters
$sqlSQL query to execute.
$paramsAssociative array containing extra parameters, can contain:
  • offset - The offset of the query.
  • limit - The limit of the query.
  • column - Limit returned row arrays to only contain this column.
$serverWhich server to execute the query on, either eZDBInterface::SERVER_MASTER or eZDBInterface::SERVER_SLAVE

An example would be:

$db->arrayQuery( 'SELECT * FROM eztable', array( 'limit' => 10, 'offset' => 5 ) );

Implements eZDBInterface.

eZMySQLDB::availableDatabases ( )
eZMySQLDB::beginQuery ( )

The query to start the transaction.

eZMySQLDB::bindingType ( )
virtual

Returns type of binding used in database plugin.

Implements eZDBInterface.

eZMySQLDB::bindVariable (   $value,
  $fieldDef = false 
)
virtual

Binds variable.

Implements eZDBInterface.

eZMySQLDB::bitAnd (   $arg1,
  $arg2 
)
virtual
Returns
a sql-expression(string) to generate a bit and of the argument.

Implements eZDBInterface.

eZMySQLDB::bitOr (   $arg1,
  $arg2 
)
virtual
Returns
a sql-expression(string) to generate a bit and of the argument.

Implements eZDBInterface.

eZMySQLDB::checkCharset (   $charset,
$currentCharset 
)

Checks if the requested character set matches the one used in the database.

Returns
true if it matches or false if it differs.
Parameters
[out]$currentCharsetThe charset that the database uses. will only be set if the match fails. Note: This will be specific to the database.
Note
There will be no check for databases using MySQL 4.1.0 or lower since they do not have proper character set handling.
eZMySQLDB::checkCharsetPriv (   $charset,
$currentCharset 
)
private

Referenced by checkCharset().

eZMySQLDB::close ( )
virtual

Will close the database connection.

Implements eZDBInterface.

eZMySQLDB::commitQuery ( )

The query to commit the transaction.

eZMySQLDB::concatString (   $strings = array())
virtual
Returns
a sql-expression(string) to concatenate strings.

Implements eZDBInterface.

eZMySQLDB::connect (   $server,
  $db,
  $user,
  $password,
  $socketPath,
  $charset = null,
  $port = false 
)
private

Opens a new connection to a MySQL database and returns the connection

Referenced by eZMySQLDB().

eZMySQLDB::createDatabase (   $dbName)
virtual

Create a new database

Implements eZDBInterface.

eZMySQLDB::databaseClientVersion ( )
virtual
Returns
the version of the database client or false if no version could be retrieved/

Implements eZDBInterface.

eZMySQLDB::databaseName ( )
virtual

Returns the name of driver, this is used to determine the name of the database type. For instance multiple implementations of the MySQL database will all return 'mysql'.

Implements eZDBInterface.

eZMySQLDB::databaseServerVersion ( )

Referenced by availableDatabases().

eZMySQLDB::dropTempTable (   $dropTableQuery = '',
  $server = self::SERVER_SLAVE 
)
eZMySQLDB::escapeString (   $str)
virtual

Will escape a string so it's ready to be inserted in the database.

Implements eZDBInterface.

eZMySQLDB::eZMySQLDB (   $parameters)

Create a new eZMySQLDB object and connects to the database backend.

Connect to master server

eZMySQLDB::eZTableList (   $server = eZDBInterface::SERVER_MASTER)
virtual
Returns
existing ez publish tables in database

Implements eZDBInterface.

eZMySQLDB::isCharsetSupported (   $charset)

Referenced by connect().

eZMySQLDB::lastSerialID (   $table = false,
  $column = false 
)
virtual

Returns the last serial ID generated with an auto increment field.

Implements eZDBInterface.

eZMySQLDB::lock (   $table)
virtual

Locks a table

Implements eZDBInterface.

eZMySQLDB::md5 (   $str)
virtual
Returns
a sql-expression(string) to generate a md5 sum of the string.

Implements eZDBInterface.

eZMySQLDB::query (   $sql,
  $server = false 
)
virtual

Execute a query on the global MySQL database link. If it returns an error, the script is halted and the attempted SQL query and MySQL error message are printed.

Parameters
$sqlSQL query to execute.

Implements eZDBInterface.

Referenced by arrayQuery(), beginQuery(), commitQuery(), createDatabase(), lock(), removeDatabase(), removeRelation(), rollbackQuery(), and unlock().

eZMySQLDB::relationCount (   $relationType = eZDBInterface::RELATION_TABLE)
virtual
Returns
the number of relation objects in the database for the relation type $relationType.

Implements eZDBInterface.

Referenced by relationCounts().

eZMySQLDB::relationCounts (   $relationMask)
virtual
Returns
the relation count for all relation types in the mask $relationMask.

Implements eZDBInterface.

eZMySQLDB::relationList (   $relationType = eZDBInterface::RELATION_TABLE)
virtual
Returns
the relation names in the database as an array for the relation type $relationType.

Ideally, we would have queried information_schema.KEY_COLUMN_USAGE However, a known bug causes queries on this table to potentially be VERY slow (http://bugs.mysql.com/bug.php?id=19588)

The query would look like this: SELECT table_name AS from_table, column_name AS from_column, referenced_table_name AS to_table, referenced_column_name AS to_column FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '{$this->DB}' AND REFERENCED_TABLE_NAME is not null;

Result as of MySQL 5.1.48 / August 2010:

+------------—+----------—+-------—+--------—+ | from_table | from_column | to_table | to_column | +------------—+----------—+-------—+--------—+ | ezdbfile_data | name_hash | ezdbfile | name_hash | +------------—+----------—+-------—+--------—+ 1 row in set (12.56 sec)

The only way out right now is to parse SHOW CREATE TABLE for each table and extract CONSTRAINT lines

Implements eZDBInterface.

Referenced by relationCount().

eZMySQLDB::relationMatchRegexp (   $relationType)
virtual
Returns
A regexp (PCRE) that can be used to filter out certain relation elements. If no special regexp is provided it will return false.
Parameters
$relationTypeThe type which needs to be filtered, this allows one regexp per type.

An example, will only match tables that start with 'ez'.

return "#^ez#";
Note
This function is currently used by the eZDBTool class to remove relation elements of a specific kind (Most likely eZ Publish related elements).

Implements eZDBInterface.

eZMySQLDB::relationName (   $relationType)

Local eZDBInterface::relationName() override to support the foreign keys type relation.

Parameters
$relationType
Returns
string|false

Referenced by removeRelation().

eZMySQLDB::removeDatabase (   $dbName)
virtual

Removes a database

Implements eZDBInterface.

eZMySQLDB::removeRelation (   $relationName,
  $relationType 
)
virtual

Tries to remove the relation type $relationType named $relationName

Returns
true if successful

Implements eZDBInterface.

eZMySQLDB::rollbackQuery ( )

The query to cancel the transaction.

eZMySQLDB::setError ( )
virtual

Sets the error message and error message number

Implements eZDBInterface.

Referenced by checkCharsetPriv(), connect(), createDatabase(), query(), and removeDatabase().

eZMySQLDB::subString (   $string,
  $from,
  $len = null 
)
virtual
Returns
a sql-expression(string) to get substring.

Implements eZDBInterface.

eZMySQLDB::supportedRelationTypeMask ( )
virtual
Returns
a mask of the relation type it supports.

Implements eZDBInterface.

eZMySQLDB::supportedRelationTypes ( )
virtual
Returns
an array of the relation types.

Implements eZDBInterface.

Referenced by relationCount(), and relationList().

eZMySQLDB::supportsDefaultValuesInsertion ( )
eZMySQLDB::unlock ( )
virtual

Releases table locks.

Implements eZDBInterface.

Member Data Documentation

eZMySQLDB::$TempTableList
const eZMySQLDB::RELATION_FOREIGN_KEY = 5
const eZMySQLDB::RELATION_FOREIGN_KEY_BIT = 32

The documentation for this class was generated from the following file: