Doctrine


Doctrine\DBAL\Connection
/Doctrine/DBAL/Connection.php at line 45

Class Connection

Connection

public class Connection

A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like events, transaction isolation levels, configuration, emulated transaction nesting, lazy connecting and more.

License:
http://www.opensource.org/licenses/lgpl-license.php LGPL
See Also:
www.doctrine-project.org
Since:
2.0
Version:
$Revision: 3938 $
Author:
Guilherme Blanco
Jonathan Wage
Roman Borschel
Konsta Vesterinen
Lukas Smith (MDB2 library)

Field Summary
final int

TRANSACTION_READ_COMMITTED

Constant for transaction isolation level READ COMMITTED.

final int

TRANSACTION_READ_UNCOMMITTED

Constant for transaction isolation level READ UNCOMMITTED.

final int

TRANSACTION_REPEATABLE_READ

Constant for transaction isolation level REPEATABLE READ.

final int

TRANSACTION_SERIALIZABLE

Constant for transaction isolation level SERIALIZABLE.

protected Doctrine\DBAL\Configuration

$_config

protected Doctrine\DBAL\Driver\Connection

$_conn

The wrapped driver connection.

protected Doctrine\DBAL\Driver

$_driver

The used DBAL driver.

protected Doctrine\Common\EventManager

$_eventManager

protected Doctrine\DBAL\Platforms\AbstractPlatform

$_platform

The DatabasePlatform object that provides information about the database platform used by the connection.

protected Doctrine\DBAL\Schema\SchemaManager

$_schemaManager

The schema manager.

Constructor Summary

Connection(array params, Driver driver, Configuration config, EventManager eventManager)

Initializes a new instance of the Connection class.

Method Summary
void

beginTransaction()

Starts a transaction by suspending auto-commit mode.

void

close()

Closes the connection.

void

commit()

Commits the current transaction.

boolean

connect()

Establishes the connection with the database.

mixed

convertToDatabaseValue(mixed value, string type)

Converts a given value to its database representation according to the conversion rules of a specific DBAL mapping type.

mixed

convertToPHPValue(mixed value, string type)

Converts a given value to its PHP representation according to the conversion rules of a specific DBAL mapping type.

integer

delete(mixed tableName, array identifier, string table)

Executes an SQL DELETE statement on a table.

integer

errorCode()

Fetch the SQLSTATE associated with the last database operation.

array

errorInfo()

Fetch extended error information associated with the last database operation.

integer

exec(string statement)

Execute an SQL statement and return the number of affected rows.

Doctrine\DBAL\Driver\Statement

executeQuery(string query, array params)

Executes an, optionally parameterized, SQL query.

integer

executeUpdate(string query, array params, array types)

Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.

array

fetchAll(string sql, array params)

Prepares and executes an SQL query and returns the result as an associative array.

array

fetchArray(string statement, array params)

Prepares and executes an SQL query and returns the first row of the result as a numerically indexed array.

mixed

fetchColumn(string statement, array params, int colnum)

Prepares and executes an SQL query and returns the value of a single column of the first row of the result.

array

fetchRow(string statement, array params)

Prepares and executes an SQL query and returns the first row of the result as an associative array.

Doctrine\DBAL\Configuration

getConfiguration()

Gets the Configuration used by the Connection.

string

getDatabase()

Gets the name of the database this Connection is connected to.

Doctrine\DBAL\Platforms\AbstractPlatform

getDatabasePlatform()

Gets the DatabasePlatform for the connection.

Doctrine\DBAL\Driver

getDriver()

Gets the DBAL driver instance.

Doctrine\Common\EventManager

getEventManager()

Gets the EventManager used by the Connection.

string

getHost()

Gets the hostname of the currently connected database.

array

getParams()

Gets the parameters used during instantiation.

string

getPassword()

Gets the password used by this connection.

mixed

getPort()

Gets the port of the currently connected database.

boolean

getRollbackOnly()

Check whether the current transaction is marked for rollback only.

Doctrine\DBAL\Schema\SchemaManager

getSchemaManager()

Gets the SchemaManager that can be used to inspect or change the database schema through the connection.

integer

getTransactionIsolation()

Gets the currently active transaction isolation level.

integer

getTransactionNestingLevel()

Returns the current transaction nesting level.

string

getUsername()

Gets the username used by this connection.

Doctrine\DBAL\Driver\Connection

getWrappedConnection()

Gets the wrapped driver connection.

integer

insert(mixed tableName, array data, string table)

Inserts a table row with specified data.

boolean

isConnected()

Whether an actual connection to the database is established.

boolean

isTransactionActive()

Checks whether a transaction is currently active.

string

lastInsertId(string seqName)

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

Doctrine\DBAL\Driver\Statement

prepare(string statement)

Prepares an SQL statement.

mixed

project(string query, array params, mixed function, Closure mapper)

Executes an, optionally parameterized, SQL query and returns the result, applying a given projection/transformation function on each row of the result.

Doctrine\DBAL\Driver\Statement

query(string statement, integer fetchType)

Executes an SQL statement, returning a result set as a Statement object.

string

quote(mixed input, string type)

Quotes a given input parameter.

string

quoteIdentifier(string str)

Quote a string so it can be safely used as a table or column name, even if it is a reserved name.

void

rollback()

Cancel any database changes done during the current transaction.

void

setCharset(string charset)

Sets the given charset on the current connection.

void

setRollbackOnly()

Marks the current transaction so that the only possible outcome for the transaction to be rolled back.

void

setTransactionIsolation(integer level)

Sets the transaction isolation level.

integer

update(mixed tableName, mixed data, array identifier, string table)

Executes an SQL UPDATE statement on a table.

Field Detail

/Doctrine/DBAL/Connection.php at line 55

TRANSACTION_READ_COMMITTED

public final int TRANSACTION_READ_COMMITTED = 2

Constant for transaction isolation level READ COMMITTED.


/Doctrine/DBAL/Connection.php at line 50

TRANSACTION_READ_UNCOMMITTED

public final int TRANSACTION_READ_UNCOMMITTED = 1

Constant for transaction isolation level READ UNCOMMITTED.


/Doctrine/DBAL/Connection.php at line 60

TRANSACTION_REPEATABLE_READ

public final int TRANSACTION_REPEATABLE_READ = 3

Constant for transaction isolation level REPEATABLE READ.


/Doctrine/DBAL/Connection.php at line 65

TRANSACTION_SERIALIZABLE

public final int TRANSACTION_SERIALIZABLE = 4

Constant for transaction isolation level SERIALIZABLE.


/Doctrine/DBAL/Connection.php at line 77

_config

protected Doctrine\DBAL\Configuration $_config


/Doctrine/DBAL/Connection.php at line 72

_conn

protected Doctrine\DBAL\Driver\Connection $_conn

The wrapped driver connection.


/Doctrine/DBAL/Connection.php at line 132

_driver

protected Doctrine\DBAL\Driver $_driver

The used DBAL driver.


/Doctrine/DBAL/Connection.php at line 82

_eventManager

protected Doctrine\Common\EventManager $_eventManager


/Doctrine/DBAL/Connection.php at line 118

_platform

protected Doctrine\DBAL\Platforms\AbstractPlatform $_platform

The DatabasePlatform object that provides information about the database platform used by the connection.


/Doctrine/DBAL/Connection.php at line 125

_schemaManager

protected Doctrine\DBAL\Schema\SchemaManager $_schemaManager

The schema manager.


Constructor Detail

/Doctrine/DBAL/Connection.php at line 149

Connection

public Connection(array params, Driver driver, Configuration config, EventManager eventManager)

Initializes a new instance of the Connection class.

Parameters:
params - The connection parameters.

Method Detail

/Doctrine/DBAL/Connection.php at line 716

beginTransaction

public void beginTransaction()

Starts a transaction by suspending auto-commit mode.


/Doctrine/DBAL/Connection.php at line 396

close

public void close()

Closes the connection.


/Doctrine/DBAL/Connection.php at line 734

commit

public void commit()

Commits the current transaction.

Throws:
If the commit failed due to no active transaction or because the transaction was marked for rollback only.

/Doctrine/DBAL/Connection.php at line 287

connect

public boolean connect()

Establishes the connection with the database.

Returns:
TRUE if the connection was successfully established, FALSE if the connection is already open.

/Doctrine/DBAL/Connection.php at line 841

convertToDatabaseValue

public mixed convertToDatabaseValue(mixed value, string type)

Converts a given value to its database representation according to the conversion rules of a specific DBAL mapping type.

Parameters:
value - The value to convert.
type - The name of the DBAL mapping type.
Returns:
The converted value.

/Doctrine/DBAL/Connection.php at line 854

convertToPHPValue

public mixed convertToPHPValue(mixed value, string type)

Converts a given value to its PHP representation according to the conversion rules of a specific DBAL mapping type.

Parameters:
value - The value to convert.
type - The name of the DBAL mapping type.
Returns:
The converted type.

/Doctrine/DBAL/Connection.php at line 376

delete

public integer delete(mixed tableName, array identifier, string table)

Executes an SQL DELETE statement on a table.

Parameters:
table - The name of the table on which to delete.
identifier - The deletion criteria. An associateve array containing column-value pairs.
Returns:
The number of affected rows.

/Doctrine/DBAL/Connection.php at line 677

errorCode

public integer errorCode()

Fetch the SQLSTATE associated with the last database operation.

Returns:
The last error code.

/Doctrine/DBAL/Connection.php at line 688

errorInfo

public array errorInfo()

Fetch extended error information associated with the last database operation.

Returns:
The last error information.

/Doctrine/DBAL/Connection.php at line 656

exec

public integer exec(string statement)

Execute an SQL statement and return the number of affected rows.

Returns:
The number of affected rows.

/Doctrine/DBAL/Connection.php at line 554

executeQuery

public Doctrine\DBAL\Driver\Statement executeQuery(string query, array params)

Executes an, optionally parameterized, SQL query.

If the query is parameterized, a prepared statement is used. If an SQLLogger is configured, the execution is logged.

Parameters:
query - The SQL query to execute.
params - The parameters to bind to the query, if any.
Returns:
The executed statement.
Internal:
PERF: Directly prepares a driver statement, not a wrapper.

/Doctrine/DBAL/Connection.php at line 626

executeUpdate

public integer executeUpdate(string query, array params, array types)

Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.

This method supports PDO binding types as well as DBAL mapping types.

Parameters:
query - The SQL query.
params - The query parameters.
types - The parameter types.
Returns:
The number of affected rows.
Internal:
PERF: Directly prepares a driver statement, not a wrapper.

/Doctrine/DBAL/Connection.php at line 525

fetchAll

public array fetchAll(string sql, array params)

Prepares and executes an SQL query and returns the result as an associative array.

Parameters:
sql - The SQL query.
params - The query parameters.

/Doctrine/DBAL/Connection.php at line 330

fetchArray

public array fetchArray(string statement, array params)

Prepares and executes an SQL query and returns the first row of the result as a numerically indexed array.

Parameters:
statement - sql query to be executed
params - prepared statement params

/Doctrine/DBAL/Connection.php at line 344

fetchColumn

public mixed fetchColumn(string statement, array params, int colnum)

Prepares and executes an SQL query and returns the value of a single column of the first row of the result.

Parameters:
statement - sql query to be executed
params - prepared statement params
colnum - 0-indexed column number to retrieve

/Doctrine/DBAL/Connection.php at line 317

fetchRow

public array fetchRow(string statement, array params)

Prepares and executes an SQL query and returns the first row of the result as an associative array.

Parameters:
statement - The SQL query.
params - The query parameters.
Todo:
Rename: fetchAssoc

/Doctrine/DBAL/Connection.php at line 256

getConfiguration

public Doctrine\DBAL\Configuration getConfiguration()

Gets the Configuration used by the Connection.


/Doctrine/DBAL/Connection.php at line 196

getDatabase

public string getDatabase()

Gets the name of the database this Connection is connected to.

Returns:
$database

/Doctrine/DBAL/Connection.php at line 276

getDatabasePlatform

public Doctrine\DBAL\Platforms\AbstractPlatform getDatabasePlatform()

Gets the DatabasePlatform for the connection.


/Doctrine/DBAL/Connection.php at line 246

getDriver

public Doctrine\DBAL\Driver getDriver()

Gets the DBAL driver instance.


/Doctrine/DBAL/Connection.php at line 266

getEventManager

public Doctrine\Common\EventManager getEventManager()

Gets the EventManager used by the Connection.


/Doctrine/DBAL/Connection.php at line 206

getHost

public string getHost()

Gets the hostname of the currently connected database.


/Doctrine/DBAL/Connection.php at line 186

getParams

public array getParams()

Gets the parameters used during instantiation.

Returns:
$params

/Doctrine/DBAL/Connection.php at line 236

getPassword

public string getPassword()

Gets the password used by this connection.


/Doctrine/DBAL/Connection.php at line 216

getPort

public mixed getPort()

Gets the port of the currently connected database.


/Doctrine/DBAL/Connection.php at line 825

getRollbackOnly

public boolean getRollbackOnly()

Check whether the current transaction is marked for rollback only.

Throws:
If no transaction is active.

/Doctrine/DBAL/Connection.php at line 796

getSchemaManager

public Doctrine\DBAL\Schema\SchemaManager getSchemaManager()

Gets the SchemaManager that can be used to inspect or change the database schema through the connection.


/Doctrine/DBAL/Connection.php at line 420

getTransactionIsolation

public integer getTransactionIsolation()

Gets the currently active transaction isolation level.

Returns:
The current transaction isolation level.

/Doctrine/DBAL/Connection.php at line 667

getTransactionNestingLevel

public integer getTransactionNestingLevel()

Returns the current transaction nesting level.

Returns:
The nesting level. A value of 0 means there's no active transaction.

/Doctrine/DBAL/Connection.php at line 226

getUsername

public string getUsername()

Gets the username used by this connection.


/Doctrine/DBAL/Connection.php at line 783

getWrappedConnection

public Doctrine\DBAL\Driver\Connection getWrappedConnection()

Gets the wrapped driver connection.


/Doctrine/DBAL/Connection.php at line 456

insert

public integer insert(mixed tableName, array data, string table)

Inserts a table row with specified data.

Parameters:
table - The name of the table to insert data into.
data - An associative array containing column-value pairs.
Returns:
The number of affected rows.

/Doctrine/DBAL/Connection.php at line 354

isConnected

public boolean isConnected()

Whether an actual connection to the database is established.


/Doctrine/DBAL/Connection.php at line 364

isTransactionActive

public boolean isTransactionActive()

Checks whether a transaction is currently active.

Returns:
TRUE if a transaction is currently active, FALSE otherwise.

/Doctrine/DBAL/Connection.php at line 705

lastInsertId

public string lastInsertId(string seqName)

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/IDENTITY columns or sequences.

Parameters:
seqName - Name of the sequence object from which the ID should be returned.
Returns:
A string representation of the last inserted ID.

/Doctrine/DBAL/Connection.php at line 536

prepare

public Doctrine\DBAL\Driver\Statement prepare(string statement)

Prepares an SQL statement.

Parameters:
statement - The SQL statement to prepare.
Returns:
The prepared statement.

/Doctrine/DBAL/Connection.php at line 588

project

public mixed project(string query, array params, mixed function, Closure mapper)

Executes an, optionally parameterized, SQL query and returns the result, applying a given projection/transformation function on each row of the result.

Parameters:
query - The SQL query to execute.
params - The parameters, if any.
mapper - The transformation function that is applied on each row. The function receives a single paramater, an array, that represents a row of the result set.
Returns:
The projected result of the query.

/Doctrine/DBAL/Connection.php at line 609

query

public Doctrine\DBAL\Driver\Statement query(string statement, integer fetchType)

Executes an SQL statement, returning a result set as a Statement object.


/Doctrine/DBAL/Connection.php at line 511

quote

public string quote(mixed input, string type)

Quotes a given input parameter.

Parameters:
input - Parameter to be quoted.
type - Type of the parameter.
Returns:
The quoted parameter.

/Doctrine/DBAL/Connection.php at line 499

quoteIdentifier

public string quoteIdentifier(string str)

Quote a string so it can be safely used as a table or column name, even if it is a reserved name.

Delimiting style depends on the underlying database platform that is being used.

NOTE: Just because you CAN use quoted identifiers does not mean you SHOULD use them. In general, they end up causing way more problems than they solve.

Parameters:
str - The name to be quoted.
Returns:
The quoted name.

/Doctrine/DBAL/Connection.php at line 760

rollback

public void rollback()

Cancel any database changes done during the current transaction.

this method can be listened with onPreTransactionRollback and onTransactionRollback eventlistener methods

Throws:
If the rollback operation failed.

/Doctrine/DBAL/Connection.php at line 481

setCharset

public void setCharset(string charset)

Sets the given charset on the current connection.

Parameters:
charset - The charset to set.

/Doctrine/DBAL/Connection.php at line 811

setRollbackOnly

public void setRollbackOnly()

Marks the current transaction so that the only possible outcome for the transaction to be rolled back.

Throws:
If no transaction is active.

/Doctrine/DBAL/Connection.php at line 408

setTransactionIsolation

public void setTransactionIsolation(integer level)

Sets the transaction isolation level.

Parameters:
level - The level to set.

/Doctrine/DBAL/Connection.php at line 432

update

public integer update(mixed tableName, mixed data, array identifier, string table)

Executes an SQL UPDATE statement on a table.

Parameters:
table - The name of the table to update.
identifier - The update criteria. An associative array containing column-value pairs.
Returns:
The number of affected rows.

Doctrine