eZPublish  3.8
eZDBInterface Class Referenceabstract

The eZDBInterface defines the interface for all database implementations. More...

+ Inheritance diagram for eZDBInterface:

Public Member Functions

 arrayQuery ($sql, $params=array())
 
attribute ($name)
 
 attributes ()
 
 availableDatabases ()
 
 begin ()
 
 beginQuery ()
 
 bindingType ()
 
 bindVariable ($value, $fieldDef=false)
 
 charset ()
 
 checkCharset ($charset, &$currentCharset)
 
 close ()
 
 commit ()
 
 commitQuery ()
 
 connectRetryCount ()
 
 connectRetryWaitTime ()
 
 createDatabase ()
 
 createTempTable ($createTableQuery= '')
 
 databaseClientVersion ()
 
 databaseName ()
 
 databaseServerVersion ()
 
 dropTempTable ($dropTableQuery= '')
 
 errorMessage ()
 
 errorNumber ()
 
 escapeString ($str)
 
 eZDBInterface ($parameters)
 
 eZTableList ()
 
 generateFailedTransactionStack ()
 
 generateUniqueTempTableName ($pattern, $randomizeIndex=false)
 
 hasAttribute ($name)
 
 hasRequiredServerVersion ($minVersion, $name=false)
 
 implodeWithTypeCast ($glue, &$pieces, $type)
 
 insertFile ($path, $sqlFile, $usePathType=true)
 
 invalidateTransaction ()
 
 isCharsetSupported ($charset)
 
 isTransactionValid ()
 
 lastSerialID ($table, $column)
 
 lock ($table)
 
 query ($sql)
 
 relationCount ($relationType=EZ_DB_RELATION_TABLE)
 
 relationCounts ($relationMask)
 
 relationList ($relationType=EZ_DB_RELATION_TABLE)
 
 relationMatchRegexp ($relationType)
 
 removeRelation ($relationName, $relationType)
 
 rollback ()
 
 rollbackQuery ()
 
 setError ()
 
 setIsSQLOutputEnabled ($enabled)
 
 socketPath ()
 
 supportedRelationTypeMask ()
 
 supportedRelationTypes ()
 
 transactionCounter ()
 
 unlock ()
 
 usesBuiltinEncoding ()
 
 useShortNames ()
 
 version ()
 

Protected Member Functions

 isConnected ()
 
 relationName ($relationType)
 
 reportError ()
 

Protected Attributes

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

Private Member Functions

 endTime ()
 
 endTimer ()
 
 generateFailedTransactionStackEntry ($stack, $indentCount)
 
 generateTraceEntry ($entry)
 
 prepareSqlQuery (&$fd, &$buffer)
 
 reportQuery ($class, $sql, $numRows, $timeTaken)
 
 startTime ()
 
 startTimer ()
 
 timeTaken ()
 

Detailed Description

The eZDBInterface defines the interface for all database implementations.

See Also
eZDB

Member Function Documentation

eZDBInterface::arrayQuery (   $sql,
  $params = array() 
)
pure 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.

An example would be:

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

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

& eZDBInterface::attribute (   $name)
Returns
the value of the attribute $name if it exists, otherwise null.
eZDBInterface::attributes ( )
Returns
the available attributes for this database handler.
eZDBInterface::availableDatabases ( )

Return alvailable databases in database.

Returns
array of available databases, null of none available false if listing databases not supported by database
eZDBInterface::begin ( )

Begin a new transaction. If we are already in transaction then we omit this new transaction and its matching commit or rollback.

Referenced by eZPostgreSQLDB\lock().

eZDBInterface::beginQuery ( )

The query to start a transaction. This function must be reimplemented in the subclasses.

Referenced by begin().

eZDBInterface::bindingType ( )
pure virtual

Returns type of binding used in database plugin.

Implemented in eZMySQLDB, and eZPostgreSQLDB.

eZDBInterface::bindVariable (   $value,
  $fieldDef = false 
)
pure virtual

Binds variable.

eZDBInterface::charset ( )

Returns the charset which the database is encoded in.

See Also
usesBuiltinEncoding
eZDBInterface::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
The default is to always return true, see the specific database handler for more information.
eZDBInterface::close ( )
pure virtual

Will close the database connection.

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

eZDBInterface::commit ( )

Commits the current transaction. If this is not the outermost it will not commit to the database immediately but instead decrease the transaction counter.

If the current transaction had any errors in it the transaction will be rollbacked instead of commited. This ensures that the database is in a valid state. Also the PHP execution will be stopped.

Returns
true if the transaction was successful, false otherwise.

Referenced by eZPostgreSQLDB\unlock().

eZDBInterface::commitQuery ( )

The query to commit the transaction. This function must be reimplemented in the subclasses.

Referenced by commit().

eZDBInterface::connectRetryCount ( )
Returns
the number of times the db handler should try to reconnect if it fails.

Referenced by eZMySQLDB\connect(), and eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::connectRetryWaitTime ( )
Returns
the number of seconds the db handler should wait before rereconnecting.
Note
Currently returns 3 seconds.

Referenced by eZMySQLDB\connect(), and eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::createDatabase ( )
pure virtual

Create a new database

eZDBInterface::createTempTable (   $createTableQuery = '')

Create a new temporary table

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

Implemented in eZMySQLDB.

eZDBInterface::databaseName ( )
pure 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'.

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

Referenced by hasRequiredServerVersion(), and insertFile().

eZDBInterface::databaseServerVersion ( )
Returns
the version of the database server or false if no version could be retrieved/

Referenced by hasRequiredServerVersion().

eZDBInterface::dropTempTable (   $dropTableQuery = '')

Drop temporary table

eZDBInterface::endTime ( )
private
Returns
the micro time when the timer was ended or false if no timer.
eZDBInterface::endTimer ( )
private

Stops the current timer and calculates the time taken.

See Also
startTimer, timeTaken

Referenced by eZPostgreSQLDB\query(), and eZMySQLDB\query().

eZDBInterface::errorMessage ( )

Returns the error message

eZDBInterface::errorNumber ( )

Returns the error number

Referenced by eZMySQLDB\availableDatabases(), and insertFile().

eZDBInterface::escapeString (   $str)
pure virtual

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

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

eZDBInterface::eZDBInterface (   $parameters)

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

Referenced by eZMySQLDB\eZMySQLDB(), eZNullDB\eZNullDB(), and eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::eZTableList ( )
pure virtual
Returns
existing ez publish tables in database

Implemented in eZMySQLDB, and eZPostgreSQLDB.

Referenced by generateUniqueTempTableName().

eZDBInterface::generateFailedTransactionStack ( )

Goes through the transaction stack tree $this->TransactionStackTree and generates the text output for it and returns it.

Returns
The generated string or false if it is disabled.
eZDBInterface::generateFailedTransactionStackEntry (   $stack,
  $indentCount 
)
private

Recursive helper function for generating stack tree output.

Returns
The generated string

Referenced by generateFailedTransactionStack().

eZDBInterface::generateTraceEntry (   $entry)
private

Helper function for generating output for one stack-trace entry.

Returns
The generated string

Referenced by generateFailedTransactionStackEntry().

eZDBInterface::generateUniqueTempTableName (   $pattern,
  $randomizeIndex = false 
)

Generate unique table name basing on the given pattern. If the pattern contains a (%) character then the character is replaced with a part providing uniqueness (e.g. random number).

eZDBInterface::hasAttribute (   $name)
Returns
true if the attribute $name exists for this database handler.
eZDBInterface::hasRequiredServerVersion (   $minVersion,
  $name = false 
)

Checks if the version number of the server is equal or larger than $minVersion. Will also check if the database type is correct if $name is set.

Parameters
$minVersionA string denoting the min. required version.
$nameThe name of the database type it requires or false if it does not matter.
Returns
true if the server fulfills the requirements.
eZDBInterface::implodeWithTypeCast (   $glue,
$pieces,
  $type 
)

Casts elements of $pieces to type $type and returns them as string separated by $glue.

Parameters
$glueThe separator. $pieces The array containing the elements. $type The type to cast to.

Example:

implodeWithTypeCast( ',', $myArray, 'int' )
eZDBInterface::insertFile (   $path,
  $sqlFile,
  $usePathType = true 
)

Inserts the SQL file $sqlFile found in the path $path into the currently connected database.

Returns
true if succesful.
eZDBInterface::invalidateTransaction ( )

Invalidates the current transaction, see commit() for more details on this.

Returns
true if it was invalidated or false if there is no transaction to invalidate.
See Also
isTransactionValid()

Referenced by reportError().

eZDBInterface::isCharsetSupported (   $charset)
Returns
true if the charset $charset is supported by the connected database.
eZDBInterface::isTransactionValid ( )
Returns
true if the current or last running transaction was valid, false otherwise.
See Also
invalidateTransaction()
eZDBInterface::lastSerialID (   $table,
  $column 
)
pure virtual

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

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

eZDBInterface::lock (   $table)
pure virtual

Locks a table

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

eZDBInterface::prepareSqlQuery ( $fd,
$buffer 
)
private

Prepare the sql file so we can create the database.

Parameters
$fdThe file descriptor
$bufferReference to string buffer for SQL queries.

Referenced by insertFile().

eZDBInterface::query (   $sql)
pure 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.

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

Referenced by createTempTable(), dropTempTable(), and insertFile().

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

Implemented in eZMySQLDB, and eZPostgreSQLDB.

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

Implemented in eZMySQLDB, and eZPostgreSQLDB.

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

Implemented in eZMySQLDB, and eZPostgreSQLDB.

eZDBInterface::relationMatchRegexp (   $relationType)
pure 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).

Implemented in eZMySQLDB, and eZPostgreSQLDB.

eZDBInterface::relationName (   $relationType)
protected
Returns
the name of the relation type which is usable in SQL or false if unknown type.
Note
This function can be used by som database handlers which can operate on relation types using SQL.

Referenced by eZPostgreSQLDB\removeRelation(), and eZMySQLDB\removeRelation().

eZDBInterface::removeRelation (   $relationName,
  $relationType 
)
pure virtual

Tries to remove the relation type $relationType named $relationName

Returns
true if successful

Implemented in eZMySQLDB, and eZPostgreSQLDB.

eZDBInterface::reportError ( )
protected

This is called whenever an error occurs in one of the database handlers. If a transaction is active it will be invalidated as well.

Referenced by eZPostgreSQLDB\query(), and eZMySQLDB\query().

eZDBInterface::reportQuery (   $class,
  $sql,
  $numRows,
  $timeTaken 
)
private

Writes a debug notice with query information.

Referenced by eZMySQLDB\arrayQuery(), eZMySQLDB\checkCharsetPriv(), eZMySQLDB\connect(), eZPostgreSQLDB\query(), and eZMySQLDB\query().

eZDBInterface::rollback ( )

Cancels the transaction.

eZDBInterface::rollbackQuery ( )

The query to cancel the transaction. This function must be reimplemented in the subclasses.

Referenced by commit(), reportError(), and rollback().

eZDBInterface::setError ( )
pure virtual

Sets the error message and error message number

Implemented in eZMySQLDB, and eZPostgreSQLDB.

eZDBInterface::setIsSQLOutputEnabled (   $enabled)

Enabled or disables sql output.

eZDBInterface::socketPath ( )
Returns
the socket path for the database or false if no socket path was defined.
eZDBInterface::startTime ( )
private
Returns
the micro time when the timer was start or false if no timer.
eZDBInterface::startTimer ( )
private

Records the current micro time. End the timer with endTimer() and fetch the result with timeTaken();

Referenced by eZPostgreSQLDB\query(), and eZMySQLDB\query().

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

Implemented in eZMySQLDB, and eZPostgreSQLDB.

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

Implemented in eZMySQLDB, and eZPostgreSQLDB.

eZDBInterface::timeTaken ( )
private
Returns
the number of milliseconds the last operation took or false if no value.

Referenced by eZPostgreSQLDB\query(), and eZMySQLDB\query().

eZDBInterface::transactionCounter ( )
Returns
The current transaction counter.

0 means no transactions, 1 or higher means 1 or more transactions are running and a negative value means something is wrong.

eZDBInterface::unlock ( )
pure virtual

Releases table locks.

Implemented in eZMySQLDB, eZPostgreSQLDB, and eZNullDB.

eZDBInterface::usesBuiltinEncoding ( )

Returns true if the database handles encoding itself, if not all queries and returned data must be decoded yourselves.

Note
This functionality might be removed in the future
eZDBInterface::useShortNames ( )
pure virtual
Returns
if the short column names should be used insted of default ones
eZDBInterface::version ( )

Get database version number

Returns
version number false if not supported

Member Data Documentation

eZDBInterface::$Charset
protected

The charset used for the current database.

Referenced by charset().

eZDBInterface::$ConnectRetries
protected

The number of times to retry a connection if it fails.

Referenced by connectRetryCount().

eZDBInterface::$DB
protected

The current database name.

Referenced by eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::$DBConnection
protected

The current connection, false if not connection has been made.

Referenced by eZMySQLDB\query().

eZDBInterface::$DBWriteConnection
protected

Contains the write database connection if used.

Referenced by eZMySQLDB\eZMySQLDB(), and eZMySQLDB\query().

eZDBInterface::$EndTime
protected

The end time of the tiemr.

Referenced by endTime().

eZDBInterface::$ErrorMessage
protected

The database error message of the last executed function.

Referenced by errorMessage().

eZDBInterface::$ErrorNumber = 0
protected

The database error message number of the last executed function.

Referenced by errorNumber().

eZDBInterface::$InputTextCodec
protected
eZDBInterface::$IsConnected = false
protected

Contains true if we're connected to the database backend.

Referenced by isConnected().

eZDBInterface::$NumQueries = 0
protected

Contains number of queries sended to DB.

eZDBInterface::$OutputSQL
protected

Setting if SQL queries should be sent to debug output.

Referenced by insertFile().

eZDBInterface::$OutputTextCodec
protected

Instance of a textcodec which handles text conversion, may not be set if no builtin encoding is used.

eZDBInterface::$Password
protected

Stores the database connection password.

Referenced by eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::$RecordError = true
protected

If true then ErrorMessage and ErrorNumber get filled.

Referenced by begin(), commit(), eZMySQLDB\query(), reportError(), and rollback().

eZDBInterface::$Server
protected

Contains the current server.

Referenced by eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::$SlaveDB
protected

The slave database name.

eZDBInterface::$SlavePassword
protected

The slave database user password.

eZDBInterface::$SlaveServer
protected

The slave server name.

eZDBInterface::$SlaveUser
protected

The slave database user.

eZDBInterface::$SocketPath
protected

The socket path, used by MySQL.

Referenced by socketPath().

eZDBInterface::$StartTime
protected

The start time of the timer.

Referenced by startTime().

eZDBInterface::$TimeTaken
protected

The total number of milliseconds the timer took.

Referenced by timeTaken().

eZDBInterface::$TransactionCounter
protected

The transaction counter, 0 means no transaction.

Referenced by begin(), commit(), and transactionCounter().

eZDBInterface::$TransactionIsValid
protected

Flag which tells if a transaction is considered valid or not A transaction will be made invalid if SQL errors occur.

Referenced by isTransactionValid().

eZDBInterface::$UseBuiltinEncoding
protected

True if a builtin encoder is to be used, this means that all input/output text is converted.

Referenced by usesBuiltinEncoding().

eZDBInterface::$UsePersistentConnection = false
protected

If true then the database connection should be persistent.

eZDBInterface::$User
protected

Stores the database connection user.

Referenced by eZPostgreSQLDB\eZPostgreSQLDB().

eZDBInterface::$UserSlaveServer
protected

Contains true if slave servers are enabled.


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