class Doctrine_Connection_Mock extends Doctrine_Connection_Common (View source)

Doctrine_Connection_Mysql

Properties

protected Doctrine_Locator $_locator from Doctrine_Locator_Injectable
protected array $_resources from Doctrine_Locator_Injectable
static protected Doctrine_Null $_null from Doctrine_Locator_Injectable
protected array $attributes from Doctrine_Configurable
protected Doctrine_Configurable $parent from Doctrine_Configurable
protected array $_impl from Doctrine_Configurable
protected array $_params from Doctrine_Configurable
protected $dbh from Doctrine_Connection
protected array $tables from Doctrine_Connection
protected string $_name $_name from Doctrine_Connection
protected string $driverName
protected boolean $isConnected from Doctrine_Connection
protected array $supported from Doctrine_Connection
protected array $pendingAttributes from Doctrine_Connection
protected array $properties from Doctrine_Connection
protected array $serverInfo from Doctrine_Connection
protected $options from Doctrine_Connection
protected $_count from Doctrine_Connection
protected array $_usedNames from Doctrine_Connection

Methods

setLocator(Doctrine_Locator $locator)

setLocator this method can be used for setting the locator object locally

getLocator()

getLocator returns the locator associated with this object

mixed
locate(string $name)

locate locates a resource by given name and returns it

bind($name, $resource)

bind binds a resource to a name

static void
initNullObject(Doctrine_Null $null)

initNullObject initializes the null object

static Doctrine_Null
getNullObject()

getNullObject returns the null object associated with this object

void
setAttribute(mixed $attribute, mixed $value)

setAttribute sets an attribute

getParams($namespace = null)

No description

getParamNamespaces()

No description

setParam($name, $value, $namespace = null)

No description

getParam($name, $namespace = null)

No description

setImpl(string $template, string $class)

setImpl binds given class to given template name

string
getImpl($template)

getImpl returns the implementation for given class

hasImpl($template)

No description

void
setEventListener(Doctrine_EventListener $listener)

No description

addRecordListener($listener, $name = null)

addRecordListener

addListener($listener, $name = null)

addListener

mixed
getAttribute(integer $attribute)

getAttribute retrieves a database connection attribute

void
unsetAttribute(integer $attribute)

Unset an attribute from this levels attributes

array
getAttributes()

getAttributes returns all attributes as an array

setCharset(string $charset)

Set the charset

mixed
getCharset()

Get the charset

setCollate(string $collate)

Set the collate

mixed
getCollate()

Get the collate

void
setParent(Doctrine_Configurable $component)

sets a parent for this configurable component the parent must be configurable component itself

getParent()

getParent returns the parent of this component

__construct(Doctrine_Manager $manager, $adapter)

the constructor

boolean
isConnected()

Check wherther the connection to the database has been made yet

void
getOptions()

getOptions

void
getOption(string $option)

getOption

void
setOption($option, $value)

setOption

static 
getAvailableDrivers()

returns an array of available PDO drivers

static array
getSupportedDrivers()

Returns an array of supported drivers by Doctrine

string
getName()

getName returns the name of this driver

void
setName(string $name)

setName

void
getDriverName()

getDriverName

__get(string $name)

__get lazy loads given module and returns it

getManager()

returns the manager that created this connection

PDO
getDbh()

returns the database handler of which this connection uses

boolean
connect()

connect connects into database

incrementQueryCount()

No description

driverName($name)

converts given driver name

boolean
supports(string $feature)

supports

replace(Doctrine_Table $table, array $fields, array $keys)

No description

integer
delete(Doctrine_Table $table, array $identifier)

deletes table row(s) matching the specified identifier

integer
update(Doctrine_Table $table, array $fields, array $identifier)

Updates table row(s) with specified data.

integer
insert(Doctrine_Table $table, array $fields)

Inserts a table row with specified data.

string
quoteIdentifier(string $str, bool $checkOption = true)

Quote a string so it can be safely used as a table or column name

string
quoteMultipleIdentifier(array $arr, bool $checkOption = true)

quoteMultipleIdentifier Quotes multiple identifier strings

void
convertBooleans(array $item)

convertBooleans some drivers need the boolean values to be converted into integers when using DQL API

string
quote(mixed $input, string $type = null)

quote quotes given input parameter

void
setDateFormat(string $format = null)

Set the date/time format for the current connection

array
fetchAll(string $statement, array $params = array())

fetchAll

mixed
fetchOne(string $statement, array $params = array(), int $colnum = 0)

fetchOne

array
fetchRow(string $statement, array $params = array())

fetchRow

array
fetchArray(string $statement, array $params = array())

fetchArray

array
fetchColumn(string $statement, array $params = array(), int $colnum = 0)

fetchColumn

array
fetchAssoc(string $statement, array $params = array())

fetchAssoc

array
fetchBoth(string $statement, array $params = array())

fetchBoth

query(string $query, array $params = array(), int $hydrationMode = null)

query queries the database using Doctrine Query Language returns a collection of Doctrine_Record objects

prepare(string $statement)

prepare

queryOne(string $query, array $params = array())

query queries the database using Doctrine Query Language and returns the first record found

select(string $query, integer $limit = 0, integer $offset = 0)

queries the database with limit and offset added to the query and returns a Doctrine_Connection_Statement object

standaloneQuery(string $query, array $params = array())

standaloneQuery

execute(string $query, array $params = array())

execute

integer
exec(string $query, array $params = array())

exec

rethrowException(Exception $e, $invoker, $query = null)

rethrowException

boolean
hasTable(mixed $name)

hasTable whether or not this connection has table $name initialized

getTable(string $name)

returns a table object for given component name

array
getTables()

returns an array of all initialized tables

getIterator()

returns an iterator that iterators through all initialized table objects

integer
count()

returns the count of initialized table objects

boolean
addTable(Doctrine_Table $table)

addTable adds a Doctrine_Table object into connection registry

create(string $name)

create creates a record

createQuery()

Creates a new Doctrine_Query object that operates on this connection.

void
flush()

flush saves all the records from all tables this operation is isolated using a transaction

void
clear()

clear clears all repositories

void
evictTables()

evictTables evicts all tables

void
close()

close closes the connection

integer
getTransactionLevel()

get the current transaction nesting level

integer
errorCode()

errorCode Fetch the SQLSTATE associated with the last operation on the database handle

array
errorInfo()

errorInfo Fetch extended error information associated with the last operation on the database handle

lastInsertId(string $table = null, string $field = null)

lastInsertId

integer
beginTransaction(string $savepoint = null)

beginTransaction Start a transaction or set a savepoint.

beginInternalTransaction($savepoint = null)

No description

boolean
commit(string $savepoint = null)

commit Commit the database changes done during a transaction that is in progress or release a savepoint. This function may only be called when auto-committing is disabled, otherwise it will fail.

boolean
rollback(string $savepoint = null)

rollback Cancel any database changes done during a transaction or since a specific savepoint that is in progress. This function may only be called when auto-committing is disabled, otherwise it will fail. Therefore, a new transaction is implicitly started after canceling the pending changes.

string
createDatabase()

createDatabase

string
dropDatabase()

dropDatabase

void
getTmpConnection(string $info)

getTmpConnection

string
modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)

Adds an driver-specific LIMIT clause to the query

string
modifyLimitSubquery(Doctrine_Table $rootTable, $query, $limit = false, $offset = false, $isManip = false)

Creates dbms specific LIMIT/OFFSET SQL for the subqueries that are used in the context of the limit-subquery algorithm.

string
__toString()

returns a string representation of this object

string
serialize()

Serialize. Remove database connection(pdo) since it cannot be serialized

void
unserialize(string $serialized)

Unserialize. Recreate connection from serialized content

string
generateUniqueRelationForeignKeyName(Doctrine_Relation $relation)

Get/generate a unique foreign key name for a relationship

string
generateUniqueIndexName(string $tableName, string $fields)

Get/generate unique index name for a table name and set of fields

_generateUniqueName($type, $parts, $key, $format = '%s', $maxLength = null)

No description

Details

Doctrine_Locator_Injectable setLocator(Doctrine_Locator $locator)

setLocator this method can be used for setting the locator object locally

Parameters

Doctrine_Locator $locator the locator object

Return Value

Doctrine_Locator_Injectable this instance

Doctrine_Locator getLocator()

getLocator returns the locator associated with this object

if there are no locator locally associated then this method tries to fetch the current global locator

Return Value

Doctrine_Locator

mixed locate(string $name)

locate locates a resource by given name and returns it

if the resource cannot be found locally this method tries to use the global locator for finding the resource

Parameters

string $name the name of the resource

Return Value

mixed the located resource

Exceptions

Doctrine_Locator_Exception if the resource could not be found

See also

Doctrine_Locator::locate

Doctrine_Locator bind($name, $resource)

bind binds a resource to a name

Parameters

$name
$resource

Return Value

Doctrine_Locator this object

static void initNullObject(Doctrine_Null $null)

initNullObject initializes the null object

Parameters

Doctrine_Null $null

Return Value

void

static Doctrine_Null getNullObject()

getNullObject returns the null object associated with this object

Return Value

Doctrine_Null

void setAttribute(mixed $attribute, mixed $value)

setAttribute sets an attribute

Parameters

mixed $attribute either a Doctrine_Core::ATTR_* integer constant or a string corresponding to a constant
mixed $value the value of the attribute

Return Value

void

getParams($namespace = null)

Parameters

$namespace

getParamNamespaces()

setParam($name, $value, $namespace = null)

Parameters

$name
$value
$namespace

getParam($name, $namespace = null)

Parameters

$name
$namespace

Doctrine_Configurable setImpl(string $template, string $class)

setImpl binds given class to given template name

this method is the base of Doctrine dependency injection

Parameters

string $template name of the class template
string $class name of the class to be bound

Return Value

Doctrine_Configurable this object

string getImpl($template)

getImpl returns the implementation for given class

Parameters

$template

Return Value

string name of the concrete implementation

hasImpl($template)

Parameters

$template

void setEventListener(Doctrine_EventListener $listener)

Parameters

Doctrine_EventListener $listener

Return Value

void

Doctrine_Configurable addRecordListener($listener, $name = null)

addRecordListener

Parameters

$listener
$name

Return Value

Doctrine_Configurable this object

Doctrine_Configurable addListener($listener, $name = null)

addListener

Parameters

$listener
$name

Return Value

Doctrine_Configurable this object

mixed getAttribute(integer $attribute)

getAttribute retrieves a database connection attribute

Parameters

integer $attribute

Return Value

mixed

void unsetAttribute(integer $attribute)

Unset an attribute from this levels attributes

Parameters

integer $attribute

Return Value

void

array getAttributes()

getAttributes returns all attributes as an array

Return Value

array

setCharset(string $charset)

Set the charset

Parameters

string $charset

mixed getCharset()

Get the charset

Return Value

mixed

setCollate(string $collate)

Set the collate

Parameters

string $collate

mixed getCollate()

Get the collate

Return Value

mixed $collate

void setParent(Doctrine_Configurable $component)

sets a parent for this configurable component the parent must be configurable component itself

Parameters

Doctrine_Configurable $component

Return Value

void

Doctrine_Configurable getParent()

getParent returns the parent of this component

Return Value

Doctrine_Configurable

__construct(Doctrine_Manager $manager, $adapter)

the constructor

Parameters

Doctrine_Manager $manager
$adapter

boolean isConnected()

Check wherther the connection to the database has been made yet

Return Value

boolean

void getOptions()

getOptions

Get array of all options

Return Value

void

void getOption(string $option)

getOption

Retrieves option

Parameters

string $option

Return Value

void

void setOption($option, $value)

setOption

Set option value

Parameters

$option
$value

Return Value

void

static getAvailableDrivers()

returns an array of available PDO drivers

static array getSupportedDrivers()

Returns an array of supported drivers by Doctrine

Return Value

array $supportedDrivers

string getName()

getName returns the name of this driver

Return Value

string the name of this driver

void setName(string $name)

setName

Sets the name of the connection

Parameters

string $name

Return Value

void

void getDriverName()

getDriverName

Gets the name of the instance driver

Return Value

void

Doctrine_Connection_Module __get(string $name)

__get lazy loads given module and returns it

Parameters

string $name the name of the module to get

Return Value

Doctrine_Connection_Module connection module

Exceptions

Doctrine_Connection_Exception if trying to get an unknown module

See also

Doctrine_DataDict
Doctrine_Expression_Driver
Doctrine_Export
Doctrine_Transaction
Doctrine_Connection::$modules all availible modules

Doctrine_Manager getManager()

returns the manager that created this connection

Return Value

Doctrine_Manager

PDO getDbh()

returns the database handler of which this connection uses

Return Value

PDO the database handler

boolean connect()

connect connects into database

Return Value

boolean

incrementQueryCount()

driverName($name)

converts given driver name

Parameters

$name

boolean supports(string $feature)

supports

Parameters

string $feature the name of the feature

Return Value

boolean whether or not this drivers supports given feature

replace(Doctrine_Table $table, array $fields, array $keys)

Parameters

Doctrine_Table $table
array $fields
array $keys

integer delete(Doctrine_Table $table, array $identifier)

deletes table row(s) matching the specified identifier

Parameters

Doctrine_Table $table The table to delete data from
array $identifier An associateve array containing identifier column-value pairs.

Return Value

integer The number of affected rows

Exceptions

Doctrine_Connection_Exception if something went wrong at the database level

integer update(Doctrine_Table $table, array $fields, array $identifier)

Updates table row(s) with specified data.

Parameters

Doctrine_Table $table
array $fields
array $identifier

Return Value

integer the number of affected rows. Boolean false if empty value array was given,

Exceptions

Doctrine_Connection_Exception if something went wrong at the database level

integer insert(Doctrine_Table $table, array $fields)

Inserts a table row with specified data.

Parameters

Doctrine_Table $table
array $fields

Return Value

integer the number of affected rows. Boolean false if empty value array was given,

string quoteIdentifier(string $str, bool $checkOption = true)

Quote a string so it can be safely used as a table or column name

Delimiting style depends on which database driver is being used.

NOTE: just because you CAN use delimited identifiers doesn't mean you SHOULD use them. In general, they end up causing way more problems than they solve.

Portability is broken by using the following characters inside delimited identifiers: + backtick (`) -- due to MySQL + double quote (") -- due to Oracle + brackets ([ or ]) -- due to Access

Delimited identifiers are known to generally work correctly under the following drivers: + mssql + mysql + mysqli + oci8 + pgsql + sqlite

InterBase doesn't seem to be able to use delimited identifiers via PHP 4. They work fine under PHP 5.

Parameters

string $str identifier name to be quoted
bool $checkOption check the 'quote_identifier' option

Return Value

string quoted identifier string

string quoteMultipleIdentifier(array $arr, bool $checkOption = true)

quoteMultipleIdentifier Quotes multiple identifier strings

Parameters

array $arr identifiers array to be quoted
bool $checkOption check the 'quote_identifier' option

Return Value

string quoted identifier string

void convertBooleans(array $item)

convertBooleans some drivers need the boolean values to be converted into integers when using DQL API

This method takes care of that conversion

Parameters

array $item

Return Value

void

string quote(mixed $input, string $type = null)

quote quotes given input parameter

Parameters

mixed $input parameter to be quoted
string $type

Return Value

string

void setDateFormat(string $format = null)

Set the date/time format for the current connection

Parameters

string $format time format

Return Value

void

array fetchAll(string $statement, array $params = array())

fetchAll

Parameters

string $statement sql query to be executed
array $params prepared statement params

Return Value

array

mixed fetchOne(string $statement, array $params = array(), int $colnum = 0)

fetchOne

Parameters

string $statement sql query to be executed
array $params prepared statement params
int $colnum 0-indexed column number to retrieve

Return Value

mixed

array fetchRow(string $statement, array $params = array())

fetchRow

Parameters

string $statement sql query to be executed
array $params prepared statement params

Return Value

array

array fetchArray(string $statement, array $params = array())

fetchArray

Parameters

string $statement sql query to be executed
array $params prepared statement params

Return Value

array

array fetchColumn(string $statement, array $params = array(), int $colnum = 0)

fetchColumn

Parameters

string $statement sql query to be executed
array $params prepared statement params
int $colnum 0-indexed column number to retrieve

Return Value

array

array fetchAssoc(string $statement, array $params = array())

fetchAssoc

Parameters

string $statement sql query to be executed
array $params prepared statement params

Return Value

array

array fetchBoth(string $statement, array $params = array())

fetchBoth

Parameters

string $statement sql query to be executed
array $params prepared statement params

Return Value

array

Doctrine_Collection query(string $query, array $params = array(), int $hydrationMode = null)

query queries the database using Doctrine Query Language returns a collection of Doctrine_Record objects

$users = $conn->query('SELECT u.* FROM User u');

$users = $conn->query('SELECT u.* FROM User u WHERE u.name LIKE ?', array('someone'));

Parameters

string $query DQL query
array $params query parameters
int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

Return Value

Doctrine_Collection Collection of Doctrine_Record objects

See also

Doctrine_Query

prepare(string $statement)

prepare

Parameters

string $statement

Doctrine_Record|false queryOne(string $query, array $params = array())

query queries the database using Doctrine Query Language and returns the first record found

$user = $conn->queryOne('SELECT u.* FROM User u WHERE u.id = ?', array(1));

$user = $conn->queryOne('SELECT u.* FROM User u WHERE u.name LIKE ? AND u.password = ?', array('someone', 'password') );

Parameters

string $query DQL query
array $params query parameters

Return Value

Doctrine_Record|false Doctrine_Record object on success, boolean false on failure

See also

Doctrine_Query

Doctrine_Connection_Statement select(string $query, integer $limit = 0, integer $offset = 0)

queries the database with limit and offset added to the query and returns a Doctrine_Connection_Statement object

Parameters

string $query
integer $limit
integer $offset

Return Value

Doctrine_Connection_Statement

PDOStatement|Doctrine_Adapter_Statement standaloneQuery(string $query, array $params = array())

standaloneQuery

Parameters

string $query sql query
array $params query parameters

Return Value

PDOStatement|Doctrine_Adapter_Statement

PDOStatement|Doctrine_Adapter_Statement execute(string $query, array $params = array())

execute

Parameters

string $query sql query
array $params query parameters

Return Value

PDOStatement|Doctrine_Adapter_Statement

integer exec(string $query, array $params = array())

exec

Parameters

string $query sql query
array $params query parameters

Return Value

integer

rethrowException(Exception $e, $invoker, $query = null)

rethrowException

Parameters

Exception $e
$invoker
$query

Exceptions

Doctrine_Connection_Exception

boolean hasTable(mixed $name)

hasTable whether or not this connection has table $name initialized

Parameters

mixed $name

Return Value

boolean

Doctrine_Table getTable(string $name)

returns a table object for given component name

Parameters

string $name component name

Return Value

Doctrine_Table

array getTables()

returns an array of all initialized tables

Return Value

array

ArrayIterator getIterator()

returns an iterator that iterators through all initialized table objects

foreach ($conn as $index => $table) { print $table; // get a string representation of each table object }

Return Value

ArrayIterator SPL ArrayIterator object

integer count()

returns the count of initialized table objects

Return Value

integer

boolean addTable(Doctrine_Table $table)

addTable adds a Doctrine_Table object into connection registry

Parameters

Doctrine_Table $table a Doctrine_Table object to be added into registry

Return Value

boolean

Doctrine_Record create(string $name)

create creates a record

create creates a record

Parameters

string $name component name

Return Value

Doctrine_Record Doctrine_Record object

Doctrine_Query createQuery()

Creates a new Doctrine_Query object that operates on this connection.

Return Value

Doctrine_Query

void flush()

flush saves all the records from all tables this operation is isolated using a transaction

Return Value

void

Exceptions

PDOException if something went wrong at database level

void clear()

clear clears all repositories

Return Value

void

void evictTables()

evictTables evicts all tables

Return Value

void

void close()

close closes the connection

Return Value

void

integer getTransactionLevel()

get the current transaction nesting level

Return Value

integer

integer errorCode()

errorCode Fetch the SQLSTATE associated with the last operation on the database handle

Return Value

integer

array errorInfo()

errorInfo Fetch extended error information associated with the last operation on the database handle

Return Value

array

Doctrine_Cache_Interface getResultCacheDriver()

getResultCacheDriver

Doctrine_Cache_Interface getQueryCacheDriver()

getQueryCacheDriver

lastInsertId(string $table = null, string $field = null)

lastInsertId

Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver.

Note: This method may not return a meaningful or consistent result across different drivers, because the underlying database may not even support the notion of auto-increment fields or sequences.

Parameters

string $table name of the table into which a new row was inserted
string $field name of the field into which a new row was inserted

integer beginTransaction(string $savepoint = null)

beginTransaction Start a transaction or set a savepoint.

if trying to set a savepoint and there is no active transaction a new transaction is being started

Listeners: onPreTransactionBegin, onTransactionBegin

Parameters

string $savepoint name of a savepoint to set

Return Value

integer current transaction nesting level

Exceptions

Doctrine_Transaction_Exception if the transaction fails at database level

beginInternalTransaction($savepoint = null)

Parameters

$savepoint

boolean commit(string $savepoint = null)

commit Commit the database changes done during a transaction that is in progress or release a savepoint. This function may only be called when auto-committing is disabled, otherwise it will fail.

Listeners: onPreTransactionCommit, onTransactionCommit

Parameters

string $savepoint name of a savepoint to release

Return Value

boolean false if commit couldn't be performed, true otherwise

Exceptions

Doctrine_Transaction_Exception if the transaction fails at PDO level
Doctrine_Validator_Exception if the transaction fails due to record validations

boolean rollback(string $savepoint = null)

rollback Cancel any database changes done during a transaction or since a specific savepoint that is in progress. This function may only be called when auto-committing is disabled, otherwise it will fail. Therefore, a new transaction is implicitly started after canceling the pending changes.

this method can be listened with onPreTransactionRollback and onTransactionRollback eventlistener methods

Parameters

string $savepoint name of a savepoint to rollback to

Return Value

boolean false if rollback couldn't be performed, true otherwise

Exceptions

Doctrine_Transaction_Exception if the rollback operation fails at database level

string createDatabase()

createDatabase

Issue create database command for this instance of Doctrine_Connection

Return Value

string Doctrine_Exception catched in case of failure

string dropDatabase()

dropDatabase

Issue drop database command for this instance of Doctrine_Connection

Return Value

string success string. Doctrine_Exception if operation failed

void getTmpConnection(string $info)

getTmpConnection

Create a temporary connection to the database with the user credentials. This is so the user can make a connection to a db server. Some dbms allow connections with no database, but some do not. In that case we have a table which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc. This value is set in the Doctrine_Export_{DRIVER} classes if required

Parameters

string $info

Return Value

void

string modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)

Adds an driver-specific LIMIT clause to the query

Parameters

$query
$limit
$offset
$isManip

Return Value

string

string modifyLimitSubquery(Doctrine_Table $rootTable, $query, $limit = false, $offset = false, $isManip = false)

Creates dbms specific LIMIT/OFFSET SQL for the subqueries that are used in the context of the limit-subquery algorithm.

Parameters

Doctrine_Table $rootTable
$query
$limit
$offset
$isManip

Return Value

string

string __toString()

returns a string representation of this object

Return Value

string

string serialize()

Serialize. Remove database connection(pdo) since it cannot be serialized

Return Value

string $serialized

void unserialize(string $serialized)

Unserialize. Recreate connection from serialized content

Parameters

string $serialized

Return Value

void

string generateUniqueRelationForeignKeyName(Doctrine_Relation $relation)

Get/generate a unique foreign key name for a relationship

Parameters

Doctrine_Relation $relation Relation object to generate the foreign key name for

Return Value

string $fkName

string generateUniqueIndexName(string $tableName, string $fields)

Get/generate unique index name for a table name and set of fields

Parameters

string $tableName The name of the table the index exists
string $fields The fields that makes up the index

Return Value

string $indexName The name of the generated index

protected _generateUniqueName($type, $parts, $key, $format = '%s', $maxLength = null)

Parameters

$type
$parts
$key
$format
$maxLength