eZ Publish  [trunk]
eZMySQLiDB Class Reference

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

+ Inheritance diagram for eZMySQLiDB:
+ Collaboration diagram for eZMySQLiDB:

List of all members.

Public Member Functions

 arrayQuery ($sql, $params=array(), $server=false)
 Executes an SQL query and returns the result as an array of accociative arrays.
 availableDatabases ()
 Returns an array of available databases in the database, null of none available, false if listing databases not supported by database.
 beginQuery ()
 bindingType ()
 Returns type of binding used in database plugin.
 bindVariable ($value, $fieldDef=false)
 Binds variable.
 bitAnd ($arg1, $arg2)
 Returns a sql-expression(string) to generate a bit and of the argument.
 bitOr ($arg1, $arg2)
 Returns a sql-expression(string) to generate a bit and of the argument.
 checkCharset ($charset, &$currentCharset)
 close ()
 Will close the database connection.
 commitQuery ()
 concatString ($strings=array())
 Returns a sql-expression(string) to concatenate strings.
 createDatabase ($dbName)
 Create a new database.
 databaseClientVersion ()
 Returns the version of the database client or false if no version could be retrieved/.
 databaseName ()
 Returns the name of driver, this is used to determine the name of the database type.
 databaseServerVersion ()
 Returns the version of the database server or false if no version could be retrieved/.
 dropTempTable ($dropTableQuery= '', $server=self::SERVER_SLAVE)
 Drop temporary table.
 escapeString ($str)
 Will escape a string so it's ready to be inserted in the database.
 eZMySQLiDB ($parameters)
 eZTableList ($server=eZDBInterface::SERVER_MASTER)
 Returns the existing ez publish tables in database.
 isCharsetSupported ($charset)
 Returns true if the charset $charset is supported by the connected database.
 lastSerialID ($table=false, $column=false)
 Returns the last serial ID generated with an auto increment field.
 lock ($table)
 Locks one or several tables.
 md5 ($str)
 Returns a sql-expression(string) to generate a md5 sum of the string.
 query ($sql, $server=false)
 Execute a query on the global MySQL database link.
 relationCount ($relationType=eZDBInterface::RELATION_TABLE)
 Returns the number of relation objects in the database for the relation type $relationType.
 relationCounts ($relationMask)
 Returns the relation count for all relation types in the mask $relationMask.
 relationList ($relationType=eZDBInterface::RELATION_TABLE)
 Returns the relation names in the database as an array for the relation type $relationType.
 relationMatchRegexp ($relationType)
 Return A regexp (PCRE) that can be used to filter out certain relation elements.
 relationName ($relationType)
 Local eZDBInterface::relationName() override to support the foreign keys type relation.
 removeDatabase ($dbName)
 Removes a database.
 removeRelation ($relationName, $relationType)
 Tries to remove the relation type $relationType named $relationName.
 rollbackQuery ()
 setError ($connection=false)
 Sets the internal error messages & number.
 subString ($string, $from, $len=null)
 Returns a sql-expression(string) to get substring.
 supportedRelationTypeMask ()
 Returns a mask of the relation type it supports.
 supportedRelationTypes ()
 Returns an array of the relation types.
 supportsDefaultValuesInsertion ()
 Returns true if the database handler support the insertion of default values, false if not.
 unlock ()
 Releases table locks.

Public Attributes

const RELATION_FOREIGN_KEY = 5
const RELATION_FOREIGN_KEY_BIT = 32

Protected Attributes

 $TempTableList

Private Member Functions

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

Detailed Description

The eZMySQLiDB class provides MySQL implementation of the database interface.

eZMySQLiDB is the MySQL implementation of eZDB.

See also:
eZDB

Definition at line 20 of file ezmysqlidb.php.


Member Function Documentation

eZMySQLiDB::arrayQuery ( sql,
params = array(),
server = false 
)

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

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

Parameters:
string$sqlSQL query to execute.
array$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.
int | bool$serverWhich server to execute the query on, either eZDBInterface::SERVER_MASTER or eZDBInterface::SERVER_SLAVE
Returns:
array

Reimplemented from eZDBInterface.

Definition at line 437 of file ezmysqlidb.php.

Returns an array of available databases in the database, null of none available, false if listing databases not supported by database.

Returns:
array|null|bool

Reimplemented from eZDBInterface.

Definition at line 893 of file ezmysqlidb.php.

The query to start the transaction.

Reimplemented from eZDBInterface.

Definition at line 796 of file ezmysqlidb.php.

Returns type of binding used in database plugin.

Returns:
int

Reimplemented from eZDBInterface.

Definition at line 173 of file ezmysqlidb.php.

eZMySQLiDB::bindVariable ( value,
fieldDef = false 
)

Binds variable.

Parameters:
mixed$value
mixed$fieldDef
Returns:
mixed

Reimplemented from eZDBInterface.

Definition at line 178 of file ezmysqlidb.php.

eZMySQLiDB::bitAnd ( arg1,
arg2 
)

Returns a sql-expression(string) to generate a bit and of the argument.

Parameters:
string$arg1
string$arg2
Returns:
string

Reimplemented from eZDBInterface.

Definition at line 544 of file ezmysqlidb.php.

eZMySQLiDB::bitOr ( arg1,
arg2 
)

Returns a sql-expression(string) to generate a bit and of the argument.

Parameters:
string$arg1
string$arg2
Returns:
string

Reimplemented from eZDBInterface.

Definition at line 549 of file ezmysqlidb.php.

eZMySQLiDB::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.

Reimplemented from eZDBInterface.

Definition at line 191 of file ezmysqlidb.php.

eZMySQLiDB::checkCharsetPriv ( charset,
&$  currentCharset 
) [private]

Definition at line 214 of file ezmysqlidb.php.

Referenced by checkCharset().

Will close the database connection.

Returns:
void

Reimplemented from eZDBInterface.

Definition at line 841 of file ezmysqlidb.php.

The query to commit the transaction.

Reimplemented from eZDBInterface.

Definition at line 804 of file ezmysqlidb.php.

eZMySQLiDB::concatString ( strings = array())

Returns a sql-expression(string) to concatenate strings.

Parameters:
array$strings
Returns:
string

Reimplemented from eZDBInterface.

Definition at line 533 of file ezmysqlidb.php.

eZMySQLiDB::connect ( server,
db,
user,
password,
socketPath,
charset = null,
port = false 
) [private]

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

Definition at line 84 of file ezmysqlidb.php.

Referenced by eZMySQLiDB().

Create a new database.

Parameters:
string$dbName
Returns:
void

Reimplemented from eZDBInterface.

Definition at line 851 of file ezmysqlidb.php.

Returns the version of the database client or false if no version could be retrieved/.

Returns:
string|bool

Reimplemented from eZDBInterface.

Definition at line 937 of file ezmysqlidb.php.

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'.

Returns:
string

Reimplemented from eZDBInterface.

Definition at line 168 of file ezmysqlidb.php.

Returns the version of the database server or false if no version could be retrieved/.

Returns:
string|bool

Reimplemented from eZDBInterface.

Definition at line 922 of file ezmysqlidb.php.

Referenced by checkCharset().

eZMySQLiDB::dropTempTable ( dropTableQuery = '',
server = self::SERVER_SLAVE 
)

Drop temporary table.

Parameters:
string$dropTableQuery
int$server
Returns:
void

Reimplemented from eZDBInterface.

Definition at line 957 of file ezmysqlidb.php.

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

Parameters:
string$str
Returns:
string mixed

Reimplemented from eZDBInterface.

Definition at line 828 of file ezmysqlidb.php.

eZMySQLiDB::eZMySQLiDB ( parameters)

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

Connect to master server

Definition at line 28 of file ezmysqlidb.php.

Returns the existing ez publish tables in database.

Parameters:
int$server
Returns:
array

Reimplemented from eZDBInterface.

Definition at line 680 of file ezmysqlidb.php.

Returns true if the charset $charset is supported by the connected database.

Parameters:
string$charset
Returns:
bool

Reimplemented from eZDBInterface.

Definition at line 947 of file ezmysqlidb.php.

eZMySQLiDB::lastSerialID ( table = false,
column = false 
)

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

Parameters:
string | bool$table
string | bool$column

Reimplemented from eZDBInterface.

Definition at line 817 of file ezmysqlidb.php.

eZMySQLiDB::lock ( table)

Locks one or several tables.

Parameters:
string | array$table

Reimplemented from eZDBInterface.

Definition at line 760 of file ezmysqlidb.php.

eZMySQLiDB::md5 ( str)

Returns a sql-expression(string) to generate a md5 sum of the string.

Parameters:
string$str
Returns:
string

Reimplemented from eZDBInterface.

Definition at line 539 of file ezmysqlidb.php.

eZMySQLiDB::query ( sql,
server = false 
)

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:
string$sqlSQL query to execute.
int | bool$server
Returns:
mixed

Reimplemented from eZDBInterface.

Definition at line 262 of file ezmysqlidb.php.

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

Returns the number of relation objects in the database for the relation type $relationType.

Parameters:
int$relationType
Returns:
int

Reimplemented from eZDBInterface.

Definition at line 572 of file ezmysqlidb.php.

Referenced by relationCounts().

eZMySQLiDB::relationCounts ( relationMask)

Returns the relation count for all relation types in the mask $relationMask.

Parameters:
int$relationMask
Returns:
int

Reimplemented from eZDBInterface.

Definition at line 564 of file ezmysqlidb.php.

Returns the relation names in the database as an array for the relation type $relationType.

Parameters:
int$relationType
Returns:
array

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

Reimplemented from eZDBInterface.

Definition at line 602 of file ezmysqlidb.php.

Referenced by relationCount().

eZMySQLiDB::relationMatchRegexp ( relationType)

Return A regexp (PCRE) that can be used to filter out certain relation elements.

If no special regexp is provided it will return false.

An example, will only match tables that start with 'ez'. return "#^ez#";

This function is currently used by the eZDBTool class to remove relation elements of a specific kind (Most likely eZ Publish related elements).

Parameters:
int$relationTypeThe type which needs to be filtered, this allows one regexp per type.
Returns:
bool

Reimplemented from eZDBInterface.

Definition at line 712 of file ezmysqlidb.php.

eZMySQLiDB::relationName ( relationType)

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

Parameters:
$relationType
Returns:
string|false

Reimplemented from eZDBInterface.

Definition at line 752 of file ezmysqlidb.php.

Referenced by removeRelation().

Removes a database.

Parameters:
string$dbName
Returns:
void

Reimplemented from eZDBInterface.

Definition at line 860 of file ezmysqlidb.php.

eZMySQLiDB::removeRelation ( relationName,
relationType 
)

Tries to remove the relation type $relationType named $relationName.

Parameters:
string$relationName
int$relationType
Returns:
bool true if successful

Reimplemented from eZDBInterface.

Definition at line 717 of file ezmysqlidb.php.

The query to cancel the transaction.

Reimplemented from eZDBInterface.

Definition at line 812 of file ezmysqlidb.php.

eZMySQLiDB::setError ( connection = false)

Sets the internal error messages & number.

Parameters:
MySQLi$connectiondatabase connection handle, overrides the current one if given

Definition at line 873 of file ezmysqlidb.php.

eZMySQLiDB::subString ( string,
from,
len = null 
)

Returns a sql-expression(string) to get substring.

Parameters:
string$string
int$from
int$len
Returns:
string

Reimplemented from eZDBInterface.

Definition at line 522 of file ezmysqlidb.php.

Returns a mask of the relation type it supports.

Returns:
int

Reimplemented from eZDBInterface.

Definition at line 554 of file ezmysqlidb.php.

Returns an array of the relation types.

Returns:
array

Reimplemented from eZDBInterface.

Definition at line 559 of file ezmysqlidb.php.

Referenced by relationCount(), and relationList().

Returns true if the database handler support the insertion of default values, false if not.

Returns:
bool

Reimplemented from eZDBInterface.

Definition at line 952 of file ezmysqlidb.php.

Releases table locks.

Returns:
void

Reimplemented from eZDBInterface.

Definition at line 785 of file ezmysqlidb.php.


Member Data Documentation

eZMySQLiDB::$TempTableList [protected]

Definition at line 963 of file ezmysqlidb.php.

Definition at line 22 of file ezmysqlidb.php.

Definition at line 23 of file ezmysqlidb.php.

Referenced by supportedRelationTypeMask().


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