123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- <?php
-
-
- namespace Doctrine\DBAL\Driver\IBMDB2;
-
- class DB2Statement implements \Doctrine\DBAL\Driver\Statement
- {
- private $_stmt = null;
-
- private $_bindParam = array();
-
-
-
- static private $_typeMap = array(
- \PDO::PARAM_INT => DB2_LONG,
- \PDO::PARAM_STR => DB2_CHAR,
- );
-
- public function __construct($stmt)
- {
- $this->_stmt = $stmt;
- }
-
-
-
- function bindValue($param, $value, $type = null)
- {
- return $this->bindParam($param, $value, $type);
- }
-
-
-
- function bindParam($column, &$variable, $type = null)
- {
- $this->_bindParam[$column] =& $variable;
-
- if ($type && isset(self::$_typeMap[$type])) {
- $type = self::$_typeMap[$type];
- } else {
- $type = DB2_CHAR;
- }
-
- if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) {
- throw new DB2Exception(db2_stmt_errormsg());
- }
- return true;
- }
-
-
-
- function closeCursor()
- {
- if (!$this->_stmt) {
- return false;
- }
-
- $this->_bindParam = array();
- db2_free_result($this->_stmt);
- $ret = db2_free_stmt($this->_stmt);
- $this->_stmt = false;
- return $ret;
- }
-
-
-
- function columnCount()
- {
- if (!$this->_stmt) {
- return false;
- }
- return db2_num_fields($this->_stmt);
- }
-
-
-
- function errorCode()
- {
- return db2_stmt_error();
- }
-
-
-
- function errorInfo()
- {
- return array(
- 0 => db2_stmt_errormsg(),
- 1 => db2_stmt_error(),
- );
- }
-
-
-
- function execute($params = null)
- {
- if (!$this->_stmt) {
- return false;
- }
-
-
-
- if ($params === null) {
- ksort($this->_bindParam);
- $params = array_values($this->_bindParam);
- }
- $retval = @db2_execute($this->_stmt, $params);
-
- if ($retval === false) {
- throw new DB2Exception(db2_stmt_errormsg());
- }
- return $retval;
- }
-
-
-
- function fetch($fetchStyle = \PDO::FETCH_BOTH)
- {
- switch ($fetchStyle) {
- case \PDO::FETCH_BOTH:
- return db2_fetch_both($this->_stmt);
- case \PDO::FETCH_ASSOC:
- return db2_fetch_assoc($this->_stmt);
- case \PDO::FETCH_NUM:
- return db2_fetch_array($this->_stmt);
- default:
- throw new DB2Exception("Given Fetch-Style " . $fetchStyle . " is not supported.");
- }
- }
-
-
-
- function fetchAll($fetchStyle = \PDO::FETCH_BOTH)
- {
- $rows = array();
- while ($row = $this->fetch($fetchStyle)) {
- $rows[] = $row;
- }
- return $rows;
- }
-
-
-
- function fetchColumn($columnIndex = 0)
- {
- $row = $this->fetch(\PDO::FETCH_NUM);
- if ($row && isset($row[$columnIndex])) {
- return $row[$columnIndex];
- }
- return false;
- }
-
-
-
- function rowCount()
- {
- return (@db2_num_rows($this->_stmt))?:0;
- }
- }
|