You are currently viewing the 1.0 branch api documentation. Switch to 1.1

1.0 Doctrine_Connection

Doctrine Connection

A wrapper layer on top of PDO / Doctrine_Adapter Doctrine_Connection is the heart of any Doctrine based application. 2. Lazy-connecting Creating an instance of Doctrine_Connection does not connect to database. Connecting to database is o

Inheritence

Doctrine_Connection  < Doctrine_Configurable

Direct Sub-Classes

Method Summary

Returns Name Description
boolean addTable
beginInternalTransaction
integer beginTransaction if trying to set a savepoint and there is no active transaction a new transaction is being started Listeners: onPreTransactionBegin, onTransactionBegin
clear
close
boolean commit Listeners: onPreTransactionCommit, onTransactionCommit
boolean connect
convertBooleans This method takes care of that conversion
integer count
create create creates a record
mixed createDatabase Issue create database command for this instance of Doctrine_Connection
createQuery
integer delete
driverName
mixed dropDatabase Issue drop database command for this instance of Doctrine_Connection
integer errorCode
array errorInfo
evictTables
exec
execute
array fetchAll
array fetchArray
array fetchAssoc
array fetchBoth
array fetchColumn
mixed fetchOne
array fetchRow
flush
mixed getAttribute
getAvailableDrivers
getCacheDriver
PDO getDbh
getDriverName Gets the name of the instance driver
ArrayIterator getIterator

 $table) {
      print $table;  // get a string representation of each table object
 }]]>
   
getManager
string getName
getOption Retrieves option
getOptions Get array of all options
getQueryCacheDriver
getResultCacheDriver
getTable
array getTables
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
integer getTransactionLevel
boolean hasTable
incrementQueryCount
mixed insert
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 e
string modifyLimitQuery Some dbms require specific functionality for this. Check the other connection adapters for examples
string modifyLimitSubquery
prepare
query

query('SELECT u.* FROM User u');

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

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')
         );]]>
   
        
mixed quote
string quoteIdentifier 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 usi
string quoteMultipleIdentifier
replace The REPLACE type of query does not make part of the SQL standards. Since practically only MySQL and SQLIte implement it natively, this type of query isemulated through this method for other DBMS using standard types of queries inside a transaction to a
rethrowException
boolean 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
select
string serialize
boolean setAttribute
setCharset
setDateFormat
setName Sets the name of the connection
setOption Set option value
standaloneQuery
boolean supports
unserialize
mixed update
__construct
__get
string __toString

Method Details

  • $table a Doctrine_Table object to be added into registry

    (boolean) addTable(( ) $table)

    addTable adds a Doctrine_Table object into connection registry


  • beginInternalTransaction($savepoint = null)


  • $savepoint name of a savepoint to set

    (integer) beginTransaction($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

    Doctrine_Connection

    throws Doctrine_Transaction_Exception if the transaction fails at database level


  • clear()

    clear clears all repositories


  • close()

    close closes the connection


  • $savepoint name of a savepoint to release

    (boolean) commit($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

    Doctrine_Connection

    throws Doctrine_Validator_Exception if the transaction fails due to record validations


  • (boolean) connect()

    connect connects into database


  • convertBooleans($item)

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

    This method takes care of that conversion


  • (integer) count()

    returns the count of initialized table objects


  • $name component name

    create($name)

    create creates a record

    create creates a record

    Doctrine_Connection


  • (mixed) createDatabase()

    Issue create database command for this instance of Doctrine_Connection

    Doctrine_Connection


  • createQuery()

    Creates a new Doctrine_Query object that operates on this connection.


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

    (integer) delete(( ) $table, $identifier)

    deletes table row(s) matching the specified identifier

    Doctrine_Connection

    throws Doctrine_Connection_Exception if something went wrong at the database level


  • driverName($name)

    converts given driver name


  • (mixed) dropDatabase()

    Issue drop database command for this instance of Doctrine_Connection

    Doctrine_Connection


  • (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


  • evictTables()

    evictTables evicts all tables


  • $query sql query
    $params query parameters

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


  • $query sql query
    $params query parameters

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


  • $statement sql query to be executed
    $params prepared statement params

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


  • $statement sql query to be executed
    $params prepared statement params

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


  • $statement sql query to be executed
    $params prepared statement params

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


  • $statement sql query to be executed
    $params prepared statement params

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


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

    (array) fetchColumn($statement, $params = array(), $colnum)


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

    (mixed) fetchOne($statement, $params = array(), $colnum)


  • $statement sql query to be executed
    $params prepared statement params

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


  • flush()

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

    throws PDOException if something went wrong at database level


  • (mixed) getAttribute($attribute)

    getAttribute retrieves a database connection attribute


  • getAvailableDrivers()

    returns an array of available PDO drivers


  • getCacheDriver()


  • (PDO) getDbh()

    returns the database handler of which this connection uses

    Doctrine_Connection


  • getDriverName()

    Gets the name of the instance driver


  • (ArrayIterator) getIterator()

    returns an iterator that iterators through all initialized table objects

    
    
    $table) {
    print $table; // get a string representation of each table object
    }]]>

    Doctrine_Connection


  • getManager()

    returns the manager that created this connection


  • (string) getName()

    getName returns the name of this driver

    Doctrine_Connection


  • getOption($option)

    Retrieves option


  • getOptions()

    Get array of all options


  • getQueryCacheDriver()


  • getResultCacheDriver()


  • $name component name

    getTable($name)

    returns a table object for given component name


  • (array) getTables()

    returns an array of all initialized tables


  • getTmpConnection($info)

    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


  • (integer) getTransactionLevel()

    get the current transaction nesting level


  • (boolean) hasTable($name)

    hasTable whether or not this connection has table $name initialized


  • incrementQueryCount()


  • $table The table to insert data into.
    $values An associateve array containing column-value pairs.

    (mixed) insert(( ) $table, $fields, $values)

    Inserts a table row with specified data.

    Doctrine_Connection


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

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

    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 e


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

    Some dbms require specific functionality for this. Check the other connection adapters for examples


  • (string) modifyLimitSubquery(( ) $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.


  • prepare($statement)


  • $query DQL query
    $params query parameters
    $hydrationMode Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD

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

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

    
    
    query('SELECT u.* FROM User u');

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

    Doctrine_Connection


  • $query DQL query
    $params query parameters

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

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

    
    
    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')
    );]]>

    Doctrine_Connection


  • $input parameter to be quoted

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

    quote quotes given input parameter


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

    (string) quoteIdentifier($str, $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 usi

    Doctrine_Connection


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

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

    quoteMultipleIdentifier Quotes multiple identifier strings

    Doctrine_Connection


  • $table name of the table on which the REPLACE query will be executed.
    $fields

    an associative array that describes the fields and the values that will be inserted or updated in the specified table. The indexes of the array are the names of all the fields of the table.

    $keys

    an array containing all key fields (primary key fields or unique index fields) for this table

    the uniqueness of a row will be determined according to the provided key fields

    this method wi

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

    Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT query, except that if there is already a row in the table with the same key field values, the REPLACE query just updates its values instead of inserting a new row.

    The REPLACE type of query does not make part of the SQL standards. Since practically only MySQL and SQLIte implement it natively, this type of query isemulated through this method for other DBMS using standard types of queries inside a transaction to a

    throws Doctrine_Connection_Exception if this driver doesn't support replace


  • rethrowException($e, $invoker)

    throws Doctrine_Connection_Exception


  • $savepoint name of a savepoint to rollback to

    (boolean) rollback($savepoint = null)

    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

    Doctrine_Connection

    throws Doctrine_Transaction_Exception if the rollback operation fails at database level


  • select($query, $limit, $offset)

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


  • (string) serialize()

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


  • (boolean) setAttribute($attribute, $value)

    setAttribute sets an attribute


  • $charset charset

    setCharset($charset)

    Set the charset on the current connection


  • $format time format

    setDateFormat($format = null)

    Set the date/time format for the current connection


  • setName($name)

    Sets the name of the connection


  • setOption($option, $value)

    Set option value


  • $query sql query
    $params query parameters

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


  • $feature the name of the feature

    (boolean) supports($feature)

    Doctrine_Connection


  • unserialize($serialized)

    Unserialize. Recreate connection from serialized content


  • $table The table to insert data into
    $values An associateve array containing column-value pairs.

    (mixed) update(( ) $table, $fields, $identifier, $values)

    Updates table row(s) with specified data

    Doctrine_Connection

    throws Doctrine_Connection_Exception if something went wrong at the database level


  • $manager the manager object
    $adapter database driver

    __construct(( ) $manager, (PDO|Doctrine_Adapter_Interface) $adapter, $user = null, $pass = null)

    the constructor


  • $name the name of the module to get

    __get($name)

    __get lazy loads given module and returns it

    Doctrine_Connection

    throws Doctrine_Connection_Exception if trying to get an unknown module


  • (string) __toString()

    returns a string representation of this object