123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
-
-
- namespace Doctrine\DBAL;
-
- use PDO,
- Doctrine\DBAL\Types\Type,
- Doctrine\DBAL\Driver\Statement as DriverStatement;
-
-
- class Statement implements DriverStatement
- {
-
-
- private $_sql;
-
-
- private $_params = array();
-
-
- private $_stmt;
-
-
- private $_platform;
-
-
- private $_conn;
-
-
-
- public function __construct($sql, Connection $conn)
- {
- $this->_sql = $sql;
- $this->_stmt = $conn->getWrappedConnection()->prepare($sql);
- $this->_conn = $conn;
- $this->_platform = $conn->getDatabasePlatform();
- }
-
-
-
- public function bindValue($name, $value, $type = null)
- {
- $this->_params[$name] = $value;
- if ($type !== null) {
- if (is_string($type)) {
- $type = Type::getType($type);
- }
- if ($type instanceof Type) {
- $value = $type->convertToDatabaseValue($value, $this->_platform);
- $bindingType = $type->getBindingType();
- } else {
- $bindingType = $type;
- }
- return $this->_stmt->bindValue($name, $value, $bindingType);
- } else {
- return $this->_stmt->bindValue($name, $value);
- }
- }
-
-
-
- public function bindParam($name, &$var, $type = PDO::PARAM_STR)
- {
- return $this->_stmt->bindParam($name, $var, $type);
- }
-
-
-
- public function execute($params = null)
- {
- $hasLogger = $this->_conn->getConfiguration()->getSQLLogger();
- if ($hasLogger) {
- $this->_conn->getConfiguration()->getSQLLogger()->startQuery($this->_sql, $this->_params);
- }
-
- $stmt = $this->_stmt->execute($params);
-
- if ($hasLogger) {
- $this->_conn->getConfiguration()->getSQLLogger()->stopQuery();
- }
- $this->_params = array();
- return $stmt;
- }
-
-
-
- public function closeCursor()
- {
- return $this->_stmt->closeCursor();
- }
-
-
-
- public function columnCount()
- {
- return $this->_stmt->columnCount();
- }
-
-
-
- public function errorCode()
- {
- return $this->_stmt->errorCode();
- }
-
-
-
- public function errorInfo()
- {
- return $this->_stmt->errorInfo();
- }
-
-
-
- public function fetch($fetchStyle = PDO::FETCH_BOTH)
- {
- return $this->_stmt->fetch($fetchStyle);
- }
-
-
-
- public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
- {
- if ($columnIndex != 0) {
- return $this->_stmt->fetchAll($fetchStyle, $columnIndex);
- }
- return $this->_stmt->fetchAll($fetchStyle);
- }
-
-
-
- public function fetchColumn($columnIndex = 0)
- {
- return $this->_stmt->fetchColumn($columnIndex);
- }
-
-
-
- public function rowCount()
- {
- return $this->_stmt->rowCount();
- }
-
-
-
- public function getWrappedStatement()
- {
- return $this->_stmt;
- }
- }
|