2008-09-12 12:51:56 +04:00
|
|
|
<?php
|
2008-09-12 21:25:38 +04:00
|
|
|
/*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
2009-02-04 19:35:36 +03:00
|
|
|
* <http://www.doctrine-project.org>.
|
2008-09-12 21:25:38 +04:00
|
|
|
*/
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\DBAL;
|
2008-09-12 21:25:38 +04:00
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
use PDO, Closure,
|
|
|
|
Doctrine\DBAL\Types\Type,
|
|
|
|
Doctrine\DBAL\Driver\Connection as DriverConnection,
|
|
|
|
Doctrine\Common\EventManager,
|
2009-12-08 22:41:47 +03:00
|
|
|
Doctrine\DBAL\DBALException;
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
/**
|
2008-12-18 17:08:11 +03:00
|
|
|
* A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like
|
2008-09-13 14:28:29 +04:00
|
|
|
* events, transaction isolation levels, configuration, emulated transaction nesting,
|
|
|
|
* lazy connecting and more.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-08-11 02:43:27 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision: 3938 $
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
|
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2010-03-29 17:20:41 +04:00
|
|
|
class Connection implements DriverConnection
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* Constant for transaction isolation level READ UNCOMMITTED.
|
|
|
|
*/
|
|
|
|
const TRANSACTION_READ_UNCOMMITTED = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant for transaction isolation level READ COMMITTED.
|
|
|
|
*/
|
|
|
|
const TRANSACTION_READ_COMMITTED = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant for transaction isolation level REPEATABLE READ.
|
|
|
|
*/
|
|
|
|
const TRANSACTION_REPEATABLE_READ = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant for transaction isolation level SERIALIZABLE.
|
|
|
|
*/
|
|
|
|
const TRANSACTION_SERIALIZABLE = 4;
|
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* The wrapped driver connection.
|
|
|
|
*
|
|
|
|
* @var Doctrine\DBAL\Driver\Connection
|
|
|
|
*/
|
|
|
|
protected $_conn;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* @var Doctrine\DBAL\Configuration
|
|
|
|
*/
|
|
|
|
protected $_config;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* @var Doctrine\Common\EventManager
|
|
|
|
*/
|
|
|
|
protected $_eventManager;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* Whether or not a connection has been established.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2009-10-23 19:03:00 +04:00
|
|
|
private $_isConnected = false;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* The transaction nesting level.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
private $_transactionNestingLevel = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently active transaction isolation level.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
private $_transactionIsolationLevel;
|
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* The parameters used during creation of the Connection instance.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2009-10-23 19:03:00 +04:00
|
|
|
private $_params = array();
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* The DatabasePlatform object that provides information about the
|
|
|
|
* database platform used by the connection.
|
|
|
|
*
|
|
|
|
* @var Doctrine\DBAL\Platforms\AbstractPlatform
|
|
|
|
*/
|
|
|
|
protected $_platform;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* The schema manager.
|
|
|
|
*
|
|
|
|
* @var Doctrine\DBAL\Schema\SchemaManager
|
|
|
|
*/
|
|
|
|
protected $_schemaManager;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
/**
|
2009-05-28 15:19:27 +04:00
|
|
|
* The used DBAL driver.
|
|
|
|
*
|
|
|
|
* @var Doctrine\DBAL\Driver
|
|
|
|
*/
|
|
|
|
protected $_driver;
|
2010-05-07 01:39:19 +04:00
|
|
|
|
2009-10-23 19:03:00 +04:00
|
|
|
/**
|
2010-05-07 01:39:19 +04:00
|
|
|
* Flag that indicates whether the current transaction is marked for rollback only.
|
|
|
|
*
|
|
|
|
* @var boolean
|
2009-10-23 19:03:00 +04:00
|
|
|
*/
|
2010-05-07 01:39:19 +04:00
|
|
|
private $_isRollbackOnly = false;
|
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
/**
|
|
|
|
* Initializes a new instance of the Connection class.
|
|
|
|
*
|
|
|
|
* @param array $params The connection parameters.
|
|
|
|
* @param Driver $driver
|
|
|
|
* @param Configuration $config
|
|
|
|
* @param EventManager $eventManager
|
|
|
|
*/
|
|
|
|
public function __construct(array $params, Driver $driver, Configuration $config = null,
|
|
|
|
EventManager $eventManager = null)
|
|
|
|
{
|
|
|
|
$this->_driver = $driver;
|
|
|
|
$this->_params = $params;
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
if (isset($params['pdo'])) {
|
|
|
|
$this->_conn = $params['pdo'];
|
|
|
|
$this->_isConnected = true;
|
|
|
|
}
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:19:27 +04:00
|
|
|
// Create default config and event manager if none given
|
|
|
|
if ( ! $config) {
|
|
|
|
$config = new Configuration();
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
2009-08-11 02:43:27 +04:00
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
if ( ! $eventManager) {
|
2009-05-28 15:19:27 +04:00
|
|
|
$eventManager = new EventManager();
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
$this->_config = $config;
|
2009-05-28 15:19:27 +04:00
|
|
|
$this->_eventManager = $eventManager;
|
2009-12-16 00:06:32 +03:00
|
|
|
if ( ! isset($params['platform'])) {
|
2009-12-08 22:41:47 +03:00
|
|
|
$this->_platform = $driver->getDatabasePlatform();
|
2009-12-16 00:06:32 +03:00
|
|
|
} else if ($params['platform'] instanceof Platforms\AbstractPlatform) {
|
2009-12-08 22:41:47 +03:00
|
|
|
$this->_platform = $params['platform'];
|
|
|
|
} else {
|
|
|
|
throw DBALException::invalidPlatformSpecified();
|
|
|
|
}
|
2010-05-07 01:39:19 +04:00
|
|
|
$this->_transactionIsolationLevel = $this->_platform->getDefaultTransactionIsolationLevel();
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
2009-05-28 15:19:27 +04:00
|
|
|
|
2009-05-28 06:04:51 +04:00
|
|
|
/**
|
2009-05-30 15:33:06 +04:00
|
|
|
* Gets the parameters used during instantiation.
|
2009-05-28 06:04:51 +04:00
|
|
|
*
|
|
|
|
* @return array $params
|
|
|
|
*/
|
|
|
|
public function getParams()
|
|
|
|
{
|
|
|
|
return $this->_params;
|
|
|
|
}
|
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
/**
|
2009-05-30 15:33:06 +04:00
|
|
|
* Gets the name of the database this Connection is connected to.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
|
|
|
* @return string $database
|
|
|
|
*/
|
|
|
|
public function getDatabase()
|
|
|
|
{
|
|
|
|
return $this->_driver->getDatabase($this);
|
|
|
|
}
|
2009-05-30 17:57:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the hostname of the currently connected database.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHost()
|
|
|
|
{
|
2009-07-15 02:36:09 +04:00
|
|
|
return isset($this->_params['host']) ? $this->_params['host'] : null;
|
2009-05-30 17:57:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the port of the currently connected database.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getPort()
|
|
|
|
{
|
2009-07-15 02:36:09 +04:00
|
|
|
return isset($this->_params['port']) ? $this->_params['port'] : null;
|
2009-05-30 17:57:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the username used by this connection.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUsername()
|
|
|
|
{
|
2009-07-15 02:36:09 +04:00
|
|
|
return isset($this->_params['user']) ? $this->_params['user'] : null;
|
2009-05-30 17:57:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the password used by this connection.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPassword()
|
|
|
|
{
|
2009-07-15 02:36:09 +04:00
|
|
|
return isset($this->_params['password']) ? $this->_params['password'] : null;
|
2009-05-30 17:57:57 +04:00
|
|
|
}
|
2009-05-28 15:30:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the DBAL driver instance.
|
|
|
|
*
|
|
|
|
* @return Doctrine\DBAL\Driver
|
|
|
|
*/
|
|
|
|
public function getDriver()
|
|
|
|
{
|
|
|
|
return $this->_driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Configuration used by the Connection.
|
|
|
|
*
|
|
|
|
* @return Doctrine\DBAL\Configuration
|
|
|
|
*/
|
|
|
|
public function getConfiguration()
|
|
|
|
{
|
|
|
|
return $this->_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the EventManager used by the Connection.
|
|
|
|
*
|
|
|
|
* @return Doctrine\Common\EventManager
|
|
|
|
*/
|
|
|
|
public function getEventManager()
|
|
|
|
{
|
|
|
|
return $this->_eventManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the DatabasePlatform for the connection.
|
|
|
|
*
|
|
|
|
* @return Doctrine\DBAL\Platforms\AbstractPlatform
|
|
|
|
*/
|
|
|
|
public function getDatabasePlatform()
|
|
|
|
{
|
|
|
|
return $this->_platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Establishes the connection with the database.
|
|
|
|
*
|
2009-12-09 15:37:57 +03:00
|
|
|
* @return boolean TRUE if the connection was successfully established, FALSE if
|
|
|
|
* the connection is already open.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function connect()
|
|
|
|
{
|
|
|
|
if ($this->_isConnected) return false;
|
|
|
|
|
|
|
|
$driverOptions = isset($this->_params['driverOptions']) ?
|
2009-05-30 15:33:06 +04:00
|
|
|
$this->_params['driverOptions'] : array();
|
|
|
|
$user = isset($this->_params['user']) ? $this->_params['user'] : null;
|
2009-05-28 15:30:27 +04:00
|
|
|
$password = isset($this->_params['password']) ?
|
2009-05-30 15:33:06 +04:00
|
|
|
$this->_params['password'] : null;
|
|
|
|
|
|
|
|
$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
|
2009-05-28 15:30:27 +04:00
|
|
|
$this->_isConnected = true;
|
|
|
|
|
2010-02-01 00:51:15 +03:00
|
|
|
if ($this->_eventManager->hasListeners(Events::postConnect)) {
|
2010-03-29 17:20:41 +04:00
|
|
|
$eventArgs = new Event\ConnectionEventArgs($this);
|
2010-02-01 00:51:15 +03:00
|
|
|
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
|
|
|
|
}
|
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-09 15:37:57 +03:00
|
|
|
* Prepares and executes an SQL query and returns the first row of the result
|
|
|
|
* as an associative array.
|
|
|
|
*
|
2009-05-28 15:30:27 +04:00
|
|
|
* @param string $statement The SQL query.
|
|
|
|
* @param array $params The query parameters.
|
|
|
|
* @return array
|
2010-05-07 01:39:19 +04:00
|
|
|
* @todo Rename: fetchAssoc
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
2010-05-07 01:39:19 +04:00
|
|
|
public function fetchRow($statement, array $params = array())
|
2009-05-28 15:30:27 +04:00
|
|
|
{
|
2010-04-01 01:13:34 +04:00
|
|
|
return $this->executeQuery($statement, $params)->fetch(PDO::FETCH_ASSOC);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-09 15:37:57 +03:00
|
|
|
* Prepares and executes an SQL query and returns the first row of the result
|
|
|
|
* as a numerically indexed array.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
|
|
|
* @param string $statement sql query to be executed
|
|
|
|
* @param array $params prepared statement params
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fetchArray($statement, array $params = array())
|
|
|
|
{
|
2010-04-01 01:13:34 +04:00
|
|
|
return $this->executeQuery($statement, $params)->fetch(PDO::FETCH_NUM);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-09 15:37:57 +03:00
|
|
|
* Prepares and executes an SQL query and returns the value of a single column
|
|
|
|
* of the first row of the result.
|
|
|
|
*
|
2009-05-28 15:30:27 +04:00
|
|
|
* @param string $statement sql query to be executed
|
|
|
|
* @param array $params prepared statement params
|
|
|
|
* @param int $colnum 0-indexed column number to retrieve
|
2009-12-09 15:37:57 +03:00
|
|
|
* @return mixed
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function fetchColumn($statement, array $params = array(), $colnum = 0)
|
|
|
|
{
|
2010-04-01 01:13:34 +04:00
|
|
|
return $this->executeQuery($statement, $params)->fetchColumn($colnum);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether an actual connection to the database is established.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isConnected()
|
|
|
|
{
|
|
|
|
return $this->_isConnected;
|
|
|
|
}
|
|
|
|
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* Checks whether a transaction is currently active.
|
|
|
|
*
|
|
|
|
* @return boolean TRUE if a transaction is currently active, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
public function isTransactionActive()
|
|
|
|
{
|
|
|
|
return $this->_transactionNestingLevel > 0;
|
|
|
|
}
|
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
/**
|
|
|
|
* Executes an SQL DELETE statement on a table.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $table The name of the table on which to delete.
|
|
|
|
* @param array $identifier The deletion criteria. An associateve array containing column-value pairs.
|
|
|
|
* @return integer The number of affected rows.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function delete($tableName, array $identifier)
|
|
|
|
{
|
|
|
|
$this->connect();
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
$criteria = array();
|
2010-03-29 17:20:41 +04:00
|
|
|
|
|
|
|
foreach (array_keys($identifier) as $columnName) {
|
|
|
|
$criteria[] = $columnName . ' = ?';
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
2009-08-11 14:51:38 +04:00
|
|
|
$query = 'DELETE FROM ' . $tableName . ' WHERE ' . implode(' AND ', $criteria);
|
2009-05-28 15:30:27 +04:00
|
|
|
|
2009-08-11 02:43:27 +04:00
|
|
|
return $this->executeUpdate($query, array_values($identifier));
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the connection.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function close()
|
|
|
|
{
|
|
|
|
unset($this->_conn);
|
2009-08-11 02:43:27 +04:00
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
$this->_isConnected = false;
|
|
|
|
}
|
|
|
|
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* Sets the transaction isolation level.
|
|
|
|
*
|
|
|
|
* @param integer $level The level to set.
|
|
|
|
*/
|
|
|
|
public function setTransactionIsolation($level)
|
|
|
|
{
|
|
|
|
$this->_transactionIsolationLevel = $level;
|
|
|
|
|
|
|
|
return $this->executeUpdate($this->_platform->getSetTransactionIsolationSQL($level));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the currently active transaction isolation level.
|
|
|
|
*
|
|
|
|
* @return integer The current transaction isolation level.
|
|
|
|
*/
|
|
|
|
public function getTransactionIsolation()
|
|
|
|
{
|
|
|
|
return $this->_transactionIsolationLevel;
|
|
|
|
}
|
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Executes an SQL UPDATE statement on a table.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $table The name of the table to update.
|
|
|
|
* @param array $identifier The update criteria. An associative array containing column-value pairs.
|
|
|
|
* @return integer The number of affected rows.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function update($tableName, array $data, array $identifier)
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
$set = array();
|
|
|
|
foreach ($data as $columnName => $value) {
|
2009-08-11 14:51:38 +04:00
|
|
|
$set[] = $columnName . ' = ?';
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$params = array_merge(array_values($data), array_values($identifier));
|
|
|
|
|
2009-08-11 14:51:38 +04:00
|
|
|
$sql = 'UPDATE ' . $tableName . ' SET ' . implode(', ', $set)
|
|
|
|
. ' WHERE ' . implode(' = ? AND ', array_keys($identifier))
|
|
|
|
. ' = ?';
|
2009-05-28 15:30:27 +04:00
|
|
|
|
2009-08-11 02:43:27 +04:00
|
|
|
return $this->executeUpdate($sql, $params);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a table row with specified data.
|
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $table The name of the table to insert data into.
|
|
|
|
* @param array $data An associative array containing column-value pairs.
|
|
|
|
* @return integer The number of affected rows.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function insert($tableName, array $data)
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
|
|
|
|
// column names are specified as array keys
|
|
|
|
$cols = array();
|
2010-03-29 17:20:41 +04:00
|
|
|
$placeholders = array();
|
2009-08-11 02:43:27 +04:00
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
foreach ($data as $columnName => $value) {
|
2009-08-11 14:51:38 +04:00
|
|
|
$cols[] = $columnName;
|
2010-03-29 17:20:41 +04:00
|
|
|
$placeholders[] = '?';
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
2009-08-11 14:51:38 +04:00
|
|
|
$query = 'INSERT INTO ' . $tableName
|
2009-08-11 02:43:27 +04:00
|
|
|
. ' (' . implode(', ', $cols) . ')'
|
2010-03-29 17:20:41 +04:00
|
|
|
. ' VALUES (' . implode(', ', $placeholders) . ')';
|
2009-05-28 15:30:27 +04:00
|
|
|
|
2009-08-11 02:43:27 +04:00
|
|
|
return $this->executeUpdate($query, array_values($data));
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Sets the given charset on the current connection.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $charset The charset to set.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function setCharset($charset)
|
|
|
|
{
|
2010-03-05 19:35:00 +03:00
|
|
|
$this->executeUpdate($this->_platform->getSetCharsetSQL($charset));
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* NOTE: Just because you CAN use quoted identifiers does not mean
|
|
|
|
* you SHOULD use them. In general, they end up causing way more
|
2009-05-28 15:30:27 +04:00
|
|
|
* problems than they solve.
|
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $str The name to be quoted.
|
|
|
|
* @return string The quoted name.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function quoteIdentifier($str)
|
|
|
|
{
|
2009-05-29 14:23:13 +04:00
|
|
|
return $this->_platform->quoteIdentifier($str);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quotes a given input parameter.
|
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param mixed $input Parameter to be quoted.
|
|
|
|
* @param string $type Type of the parameter.
|
|
|
|
* @return string The quoted parameter.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function quote($input, $type = null)
|
|
|
|
{
|
2009-09-05 22:27:37 +04:00
|
|
|
$this->connect();
|
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
return $this->_conn->quote($input, $type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-09 15:37:57 +03:00
|
|
|
* Prepares and executes an SQL query and returns the result as an associative array.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
|
|
|
* @param string $sql The SQL query.
|
|
|
|
* @param array $params The query parameters.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fetchAll($sql, array $params = array())
|
|
|
|
{
|
2010-04-01 01:13:34 +04:00
|
|
|
return $this->executeQuery($sql, $params)->fetchAll(PDO::FETCH_ASSOC);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares an SQL statement.
|
|
|
|
*
|
2009-12-09 15:37:57 +03:00
|
|
|
* @param string $statement The SQL statement to prepare.
|
2010-03-29 17:20:41 +04:00
|
|
|
* @return Doctrine\DBAL\Driver\Statement The prepared statement.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function prepare($statement)
|
|
|
|
{
|
|
|
|
$this->connect();
|
2010-03-29 17:20:41 +04:00
|
|
|
|
|
|
|
return new Statement($statement, $this);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Executes an, optionally parameterized, SQL query.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* If the query is parameterized, a prepared statement is used.
|
|
|
|
* If an SQLLogger is configured, the execution is logged.
|
|
|
|
*
|
|
|
|
* @param string $query The SQL query to execute.
|
|
|
|
* @param array $params The parameters to bind to the query, if any.
|
|
|
|
* @return Doctrine\DBAL\Driver\Statement The executed statement.
|
|
|
|
* @internal PERF: Directly prepares a driver statement, not a wrapper.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
2010-04-01 01:13:34 +04:00
|
|
|
public function executeQuery($query, array $params = array(), $types = array())
|
2009-05-28 15:30:27 +04:00
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
if ($this->_config->getSQLLogger() !== null) {
|
|
|
|
$this->_config->getSQLLogger()->logSQL($query, $params);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
|
|
|
if ($params) {
|
2009-06-14 21:34:28 +04:00
|
|
|
$stmt = $this->_conn->prepare($query);
|
2010-03-29 17:20:41 +04:00
|
|
|
if ($types) {
|
|
|
|
$this->_bindTypedValues($stmt, $params, $types);
|
|
|
|
$stmt->execute();
|
|
|
|
} else {
|
|
|
|
$stmt->execute($params);
|
|
|
|
}
|
2009-05-28 15:30:27 +04:00
|
|
|
} else {
|
|
|
|
$stmt = $this->_conn->query($query);
|
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-06-14 21:34:28 +04:00
|
|
|
return $stmt;
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-12-09 15:37:57 +03:00
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Executes an, optionally parameterized, SQL query and returns the result,
|
|
|
|
* applying a given projection/transformation function on each row of the result.
|
2009-12-09 15:37:57 +03:00
|
|
|
*
|
|
|
|
* @param string $query The SQL query to execute.
|
|
|
|
* @param array $params The parameters, if any.
|
|
|
|
* @param Closure $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.
|
2010-03-29 17:20:41 +04:00
|
|
|
* @return mixed The projected result of the query.
|
2009-12-09 15:37:57 +03:00
|
|
|
*/
|
2010-05-07 01:39:19 +04:00
|
|
|
public function project($query, array $params = array(), Closure $function)
|
2009-12-09 15:37:57 +03:00
|
|
|
{
|
|
|
|
$result = array();
|
2010-05-07 01:39:19 +04:00
|
|
|
$stmt = $this->executeQuery($query, $params);
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-12-09 15:37:57 +03:00
|
|
|
while ($row = $stmt->fetch()) {
|
2010-03-29 17:20:41 +04:00
|
|
|
$result[] = $function($row);
|
2009-12-09 15:37:57 +03:00
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-12-09 15:37:57 +03:00
|
|
|
$stmt->closeCursor();
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-12-09 15:37:57 +03:00
|
|
|
return $result;
|
|
|
|
}
|
2009-05-28 15:30:27 +04:00
|
|
|
|
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Executes an SQL statement, returning a result set as a Statement object.
|
|
|
|
*
|
|
|
|
* @param string $statement
|
|
|
|
* @param integer $fetchType
|
|
|
|
* @return Doctrine\DBAL\Driver\Statement
|
|
|
|
*/
|
|
|
|
public function query()
|
|
|
|
{
|
|
|
|
return call_user_func_array(array($this->_conn, 'query'), func_get_args());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $query The SQL query.
|
|
|
|
* @param array $params The query parameters.
|
|
|
|
* @param array $types The parameter types.
|
|
|
|
* @return integer The number of affected rows.
|
|
|
|
* @internal PERF: Directly prepares a driver statement, not a wrapper.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
2010-03-29 17:20:41 +04:00
|
|
|
public function executeUpdate($query, array $params = array(), array $types = array())
|
2009-05-28 15:30:27 +04:00
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
if ($this->_config->getSQLLogger() !== null) {
|
|
|
|
$this->_config->getSQLLogger()->logSQL($query, $params);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
if ($params) {
|
2009-06-14 21:34:28 +04:00
|
|
|
$stmt = $this->_conn->prepare($query);
|
2010-03-29 17:20:41 +04:00
|
|
|
if ($types) {
|
|
|
|
$this->_bindTypedValues($stmt, $params, $types);
|
|
|
|
$stmt->execute();
|
|
|
|
} else {
|
|
|
|
$stmt->execute($params);
|
|
|
|
}
|
2009-06-14 21:34:28 +04:00
|
|
|
$result = $stmt->rowCount();
|
2009-05-28 15:30:27 +04:00
|
|
|
} else {
|
2009-06-14 21:34:28 +04:00
|
|
|
$result = $this->_conn->exec($query);
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-06-14 21:34:28 +04:00
|
|
|
return $result;
|
2009-05-28 15:30:27 +04:00
|
|
|
}
|
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
/**
|
|
|
|
* Execute an SQL statement and return the number of affected rows.
|
|
|
|
*
|
|
|
|
* @param string $statement
|
|
|
|
* @return integer The number of affected rows.
|
|
|
|
*/
|
|
|
|
public function exec($statement)
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
return $this->_conn->exec($statement);
|
|
|
|
}
|
|
|
|
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* Returns the current transaction nesting level.
|
|
|
|
*
|
|
|
|
* @return integer The nesting level. A value of 0 means there's no active transaction.
|
|
|
|
*/
|
|
|
|
public function getTransactionNestingLevel()
|
|
|
|
{
|
|
|
|
return $this->_transactionNestingLevel;
|
|
|
|
}
|
|
|
|
|
2009-05-28 15:30:27 +04:00
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Fetch the SQLSTATE associated with the last database operation.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @return integer The last error code.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function errorCode()
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
return $this->_conn->errorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Fetch extended error information associated with the last database operation.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @return array The last error information.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
|
|
|
public function errorInfo()
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
return $this->_conn->errorInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2010-03-29 17:20:41 +04:00
|
|
|
* because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
|
|
|
|
* columns or sequences.
|
2009-05-28 15:30:27 +04:00
|
|
|
*
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param string $seqName Name of the sequence object from which the ID should be returned.
|
|
|
|
* @return string A string representation of the last inserted ID.
|
2009-05-28 15:30:27 +04:00
|
|
|
*/
|
2009-05-28 15:26:08 +04:00
|
|
|
public function lastInsertId($seqName = null)
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
return $this->_conn->lastInsertId($seqName);
|
|
|
|
}
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* Starts a transaction by suspending auto-commit mode.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function beginTransaction()
|
|
|
|
{
|
|
|
|
$this->connect();
|
|
|
|
|
|
|
|
if ($this->_transactionNestingLevel == 0) {
|
|
|
|
$this->_conn->beginTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
++$this->_transactionNestingLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Commits the current transaction.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @throws ConnectionException If the commit failed due to no active transaction or
|
|
|
|
* because the transaction was marked for rollback only.
|
|
|
|
*/
|
|
|
|
public function commit()
|
|
|
|
{
|
|
|
|
if ($this->_transactionNestingLevel == 0) {
|
|
|
|
throw ConnectionException::commitFailedNoActiveTransaction();
|
|
|
|
}
|
|
|
|
if ($this->_isRollbackOnly) {
|
|
|
|
throw ConnectionException::commitFailedRollbackOnly();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->connect();
|
|
|
|
|
|
|
|
if ($this->_transactionNestingLevel == 1) {
|
|
|
|
$this->_conn->commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
--$this->_transactionNestingLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel any database changes done during the current transaction.
|
|
|
|
*
|
|
|
|
* this method can be listened with onPreTransactionRollback and onTransactionRollback
|
|
|
|
* eventlistener methods
|
|
|
|
*
|
|
|
|
* @throws ConnectionException If the rollback operation failed.
|
|
|
|
*/
|
|
|
|
public function rollback()
|
|
|
|
{
|
|
|
|
if ($this->_transactionNestingLevel == 0) {
|
|
|
|
throw ConnectionException::rollbackFailedNoActiveTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->connect();
|
|
|
|
|
|
|
|
if ($this->_transactionNestingLevel == 1) {
|
|
|
|
$this->_transactionNestingLevel = 0;
|
|
|
|
$this->_conn->rollback();
|
|
|
|
$this->_isRollbackOnly = false;
|
|
|
|
} else {
|
|
|
|
$this->_isRollbackOnly = true;
|
|
|
|
--$this->_transactionNestingLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 15:24:22 +04:00
|
|
|
/**
|
|
|
|
* Gets the wrapped driver connection.
|
|
|
|
*
|
|
|
|
* @return Doctrine\DBAL\Driver\Connection
|
|
|
|
*/
|
|
|
|
public function getWrappedConnection()
|
|
|
|
{
|
|
|
|
$this->connect();
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-05-28 15:24:22 +04:00
|
|
|
return $this->_conn;
|
|
|
|
}
|
2009-05-28 15:13:12 +04:00
|
|
|
|
2009-05-28 15:24:22 +04:00
|
|
|
/**
|
|
|
|
* Gets the SchemaManager that can be used to inspect or change the
|
|
|
|
* database schema through the connection.
|
|
|
|
*
|
2010-05-07 01:39:19 +04:00
|
|
|
* @return Doctrine\DBAL\Schema\SchemaManager
|
2009-05-28 15:24:22 +04:00
|
|
|
*/
|
|
|
|
public function getSchemaManager()
|
|
|
|
{
|
|
|
|
if ( ! $this->_schemaManager) {
|
|
|
|
$this->_schemaManager = $this->_driver->getSchemaManager($this);
|
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2009-05-28 15:24:22 +04:00
|
|
|
return $this->_schemaManager;
|
|
|
|
}
|
2010-03-29 17:20:41 +04:00
|
|
|
|
2010-05-07 01:39:19 +04:00
|
|
|
/**
|
|
|
|
* Marks the current transaction so that the only possible
|
|
|
|
* outcome for the transaction to be rolled back.
|
|
|
|
*
|
|
|
|
* @throws ConnectionException If no transaction is active.
|
|
|
|
*/
|
|
|
|
public function setRollbackOnly()
|
|
|
|
{
|
|
|
|
if ($this->_transactionNestingLevel == 0) {
|
|
|
|
throw ConnectionException::noActiveTransaction();
|
|
|
|
}
|
|
|
|
$this->_isRollbackOnly = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the current transaction is marked for rollback only.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* @throws ConnectionException If no transaction is active.
|
|
|
|
*/
|
|
|
|
public function getRollbackOnly()
|
|
|
|
{
|
|
|
|
if ($this->_transactionNestingLevel == 0) {
|
|
|
|
throw ConnectionException::noActiveTransaction();
|
|
|
|
}
|
|
|
|
return $this->_isRollbackOnly;
|
|
|
|
}
|
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
/**
|
|
|
|
* Converts a given value to its database representation according to the conversion
|
|
|
|
* rules of a specific DBAL mapping type.
|
|
|
|
*
|
|
|
|
* @param mixed $value The value to convert.
|
|
|
|
* @param string $type The name of the DBAL mapping type.
|
|
|
|
* @return mixed The converted value.
|
|
|
|
*/
|
|
|
|
public function convertToDatabaseValue($value, $type)
|
|
|
|
{
|
|
|
|
return Type::getType($type)->convertToDatabaseValue($value, $this->_platform);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a given value to its PHP representation according to the conversion
|
|
|
|
* rules of a specific DBAL mapping type.
|
|
|
|
*
|
|
|
|
* @param mixed $value The value to convert.
|
|
|
|
* @param string $type The name of the DBAL mapping type.
|
|
|
|
* @return mixed The converted type.
|
|
|
|
*/
|
|
|
|
public function convertToPHPValue($value, $type)
|
|
|
|
{
|
|
|
|
return Type::getType($type)->convertToPHPValue($value, $this->_platform);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds a set of parameters, some or all of which are typed with a PDO binding type
|
|
|
|
* or DBAL mapping type, to a given statement.
|
|
|
|
*
|
2010-03-31 17:15:23 +04:00
|
|
|
* @param $stmt The statement to bind the values to.
|
2010-03-29 17:20:41 +04:00
|
|
|
* @param array $params The map/list of named/positional parameters.
|
|
|
|
* @param array $types The parameter types (PDO binding types or DBAL mapping types).
|
2010-03-31 17:15:23 +04:00
|
|
|
* @internal Duck-typing used on the $stmt parameter to support driver statements as well as
|
|
|
|
* raw PDOStatement instances.
|
2010-03-29 17:20:41 +04:00
|
|
|
*/
|
2010-03-31 17:15:23 +04:00
|
|
|
private function _bindTypedValues($stmt, array $params, array $types)
|
2010-03-29 17:20:41 +04:00
|
|
|
{
|
|
|
|
// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
|
|
|
|
if (is_int(key($params))) {
|
|
|
|
// Positional parameters
|
|
|
|
$typeOffset = isset($types[0]) ? -1 : 0;
|
|
|
|
$bindIndex = 1;
|
|
|
|
foreach ($params as $position => $value) {
|
|
|
|
$typeIndex = $bindIndex + $typeOffset;
|
|
|
|
if (isset($types[$typeIndex])) {
|
|
|
|
$type = $types[$typeIndex];
|
|
|
|
if (is_string($type)) {
|
|
|
|
$type = Type::getType($type);
|
|
|
|
}
|
|
|
|
if ($type instanceof Type) {
|
|
|
|
$value = $type->convertToDatabaseValue($value, $this->_platform);
|
|
|
|
$bindingType = $type->getBindingType();
|
|
|
|
} else {
|
|
|
|
$bindingType = $type; // PDO::PARAM_* constants
|
|
|
|
}
|
|
|
|
$stmt->bindValue($bindIndex, $value, $bindingType);
|
|
|
|
} else {
|
|
|
|
$stmt->bindValue($bindIndex, $value);
|
|
|
|
}
|
|
|
|
++$bindIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Named parameters
|
|
|
|
foreach ($params as $name => $value) {
|
|
|
|
if (isset($types[$name])) {
|
|
|
|
$type = $types[$name];
|
|
|
|
if (is_string($type)) {
|
|
|
|
$type = Type::getType($type);
|
|
|
|
}
|
|
|
|
if ($type instanceof Type) {
|
|
|
|
$value = $type->convertToDatabaseValue($value, $this->_platform);
|
|
|
|
$bindingType = $type->getBindingType();
|
|
|
|
} else {
|
|
|
|
$bindingType = $type; // PDO::PARAM_* constants
|
|
|
|
}
|
|
|
|
$stmt->bindValue($name, $value, $bindingType);
|
|
|
|
} else {
|
|
|
|
$stmt->bindValue($name, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-07 01:39:19 +04:00
|
|
|
}
|