eZ Publish  [trunk]
eZMySQLDB Class Reference

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

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

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.
 eZMySQLDB ($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

 $TempTableList
const RELATION_FOREIGN_KEY = 5
const RELATION_FOREIGN_KEY_BIT = 32

Private Member Functions

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

Detailed Description

The eZMySQLDB class provides MySQL implementation of the database interface.

eZMySQLDB is the MySQL implementation of eZDB.

See also:
eZDB
Deprecated:
Since 4.5 in favour of eZMySQLiDB

Definition at line 18 of file ezmysqldb.php.


Member Function Documentation

eZMySQLDB::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 444 of file ezmysqldb.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 905 of file ezmysqldb.php.

The query to start the transaction.

Reimplemented from eZDBInterface.

Definition at line 809 of file ezmysqldb.php.

Returns type of binding used in database plugin.

Returns:
int

Reimplemented from eZDBInterface.

Definition at line 180 of file ezmysqldb.php.

eZMySQLDB::bindVariable ( value,
fieldDef = false 
)

Binds variable.

Parameters:
mixed$value
mixed$fieldDef
Returns:
mixed

Reimplemented from eZDBInterface.

Definition at line 185 of file ezmysqldb.php.

eZMySQLDB::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 551 of file ezmysqldb.php.

eZMySQLDB::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 556 of file ezmysqldb.php.

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.

Reimplemented from eZDBInterface.

Definition at line 201 of file ezmysqldb.php.

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

Definition at line 222 of file ezmysqldb.php.

Referenced by checkCharset().

Will close the database connection.

Returns:
void

Reimplemented from eZDBInterface.

Definition at line 853 of file ezmysqldb.php.

The query to commit the transaction.

Reimplemented from eZDBInterface.

Definition at line 817 of file ezmysqldb.php.

eZMySQLDB::concatString ( strings = array())

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

Parameters:
array$strings
Returns:
string

Reimplemented from eZDBInterface.

Definition at line 540 of file ezmysqldb.php.

eZMySQLDB::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 82 of file ezmysqldb.php.

Referenced by eZMySQLDB().

Create a new database.

Parameters:
string$dbName
Returns:
void

Reimplemented from eZDBInterface.

Definition at line 863 of file ezmysqldb.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 949 of file ezmysqldb.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 175 of file ezmysqldb.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 935 of file ezmysqldb.php.

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

Drop temporary table.

Parameters:
string$dropTableQuery
int$server
Returns:
void

Reimplemented from eZDBInterface.

Definition at line 969 of file ezmysqldb.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 841 of file ezmysqldb.php.

eZMySQLDB::eZMySQLDB ( parameters)

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

Connect to master server

Definition at line 26 of file ezmysqldb.php.

Returns the existing ez publish tables in database.

Parameters:
int$server
Returns:
array

Reimplemented from eZDBInterface.

Definition at line 690 of file ezmysqldb.php.

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

Parameters:
string$charset
Returns:
bool

Reimplemented from eZDBInterface.

Definition at line 959 of file ezmysqldb.php.

Referenced by connect().

eZMySQLDB::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 830 of file ezmysqldb.php.

eZMySQLDB::lock ( table)

Locks one or several tables.

Parameters:
string | array$table

Reimplemented from eZDBInterface.

Definition at line 773 of file ezmysqldb.php.

eZMySQLDB::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 546 of file ezmysqldb.php.

eZMySQLDB::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 270 of file ezmysqldb.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 579 of file ezmysqldb.php.

Referenced by relationCounts().

eZMySQLDB::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 571 of file ezmysqldb.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 609 of file ezmysqldb.php.

Referenced by relationCount().

eZMySQLDB::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 724 of file ezmysqldb.php.

eZMySQLDB::relationName ( relationType)

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

Parameters:
$relationType
Returns:
string|false

Reimplemented from eZDBInterface.

Definition at line 764 of file ezmysqldb.php.

Referenced by removeRelation().

Removes a database.

Parameters:
string$dbName
Returns:
void

Reimplemented from eZDBInterface.

Definition at line 872 of file ezmysqldb.php.

eZMySQLDB::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 729 of file ezmysqldb.php.

The query to cancel the transaction.

Reimplemented from eZDBInterface.

Definition at line 825 of file ezmysqldb.php.

eZMySQLDB::setError ( connection = false)

Sets the internal error messages & number.

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

Definition at line 885 of file ezmysqldb.php.

eZMySQLDB::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 529 of file ezmysqldb.php.

Returns a mask of the relation type it supports.

Returns:
int

Reimplemented from eZDBInterface.

Definition at line 561 of file ezmysqldb.php.

Returns an array of the relation types.

Returns:
array

Reimplemented from eZDBInterface.

Definition at line 566 of file ezmysqldb.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 964 of file ezmysqldb.php.

Releases table locks.

Returns:
void

Reimplemented from eZDBInterface.

Definition at line 798 of file ezmysqldb.php.


Member Data Documentation

eZMySQLDB::$TempTableList

Definition at line 975 of file ezmysqldb.php.

Definition at line 20 of file ezmysqldb.php.

Definition at line 21 of file ezmysqldb.php.

Referenced by supportedRelationTypeMask().


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