📄 oracle.php
字号:
* @param int $cursor OPTIONAL Absolute, relative, or other. * @param int $offset OPTIONAL Number for absolute or relative cursors. * @return mixed Array, object, or scalar depending on fetch mode. * @throws Zend_Db_Statement_Exception */ public function fetch($style = null, $cursor = null, $offset = null) { if (!$this->_stmt) { return false; } if ($style === null) { $style = $this->_fetchMode; } switch ($style) { case Zend_Db::FETCH_NUM: $row = oci_fetch_row($this->_stmt); break; case Zend_Db::FETCH_ASSOC: $row = oci_fetch_assoc($this->_stmt); break; case Zend_Db::FETCH_BOTH: $row = oci_fetch_array($this->_stmt, OCI_BOTH); break; case Zend_Db::FETCH_OBJ: $row = oci_fetch_object($this->_stmt); break; case Zend_Db::FETCH_BOUND: $row = oci_fetch_array($this->_stmt, OCI_BOTH); if ($row !== false) { return $this->_fetchBound($row); } break; default: /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception( array( 'code' => 'HYC00', 'message' => "Invalid fetch mode '$style' specified" ) ); break; } if (! $row && $error = oci_error($this->_stmt)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception($error); } return $row; } /** * Returns an array containing all of the result set rows. * * @param int $style OPTIONAL Fetch mode. * @param int $col OPTIONAL Column number, if fetch mode is by column. * @return array Collection of rows, each in a format by the fetch mode. * @throws Zend_Db_Statement_Exception */ public function fetchAll($style = null, $col = 0) { if (!$this->_stmt) { return false; } // make sure we have a fetch mode if ($style === null) { $style = $this->_fetchMode; } $flags = OCI_FETCHSTATEMENT_BY_ROW; switch ($style) { case Zend_Db::FETCH_BOTH: /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception( array( 'code' => 'HYC00', 'message' => "OCI8 driver does not support fetchAll(FETCH_BOTH), use fetch() in a loop instead" ) ); // notreached $flags |= OCI_NUM; $flags |= OCI_ASSOC; break; case Zend_Db::FETCH_NUM: $flags |= OCI_NUM; break; case Zend_Db::FETCH_ASSOC: $flags |= OCI_ASSOC; break; case Zend_Db::FETCH_OBJ: break; case Zend_Db::FETCH_COLUMN: $flags = $flags &~ OCI_FETCHSTATEMENT_BY_ROW; $flags |= OCI_FETCHSTATEMENT_BY_COLUMN; $flags |= OCI_NUM; break; default: /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception( array( 'code' => 'HYC00', 'message' => "Invalid fetch mode '$style' specified" ) ); break; } $result = Array(); if ($flags != OCI_FETCHSTATEMENT_BY_ROW) { /* not Zend_Db::FETCH_OBJ */ if (! ($rows = oci_fetch_all($this->_stmt, $result, 0, -1, $flags) )) { if ($error = oci_error($this->_stmt)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception($error); } if (!$rows) { return array(); } } if ($style == Zend_Db::FETCH_COLUMN) { $result = $result[$col]; } } else { while (($row = oci_fetch_object($this->_stmt)) !== false) { $result [] = $row; } if ($error = oci_error($this->_stmt)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception($error); } } return $result; } /** * Returns a single column from the next row of a result set. * * @param int $col OPTIONAL Position of the column to fetch. * @return string * @throws Zend_Db_Statement_Exception */ public function fetchColumn($col = 0) { if (!$this->_stmt) { return false; } if (!oci_fetch($this->_stmt)) { /* TODO ERROR */ } $data = oci_result($this->_stmt, $col+1); //1-based if ($data === false) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt)); } return $data; } /** * Fetches the next row and returns it as an object. * * @param string $class OPTIONAL Name of the class to create. * @param array $config OPTIONAL Constructor arguments for the class. * @return mixed One object instance of the specified class. * @throws Zend_Db_Statement_Exception */ public function fetchObject($class = 'stdClass', array $config = array()) { if (!$this->_stmt) { return false; } $obj = oci_fetch_object($this->_stmt); if ($obj === false) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt)); } /* @todo XXX handle parameters */ return $obj; } /** * Retrieves the next rowset (result set) for a SQL statement that has * multiple result sets. An example is a stored procedure that returns * the results of multiple queries. * * @return bool * @throws Zend_Db_Statement_Exception */ public function nextRowset() { /** * @see Zend_Db_Statement_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception( array( 'code' => 'HYC00', 'message' => 'Optional feature not implemented' ) ); } /** * Returns the number of rows affected by the execution of the * last INSERT, DELETE, or UPDATE statement executed by this * statement object. * * @return int The number of rows affected. * @throws Zend_Db_Statement_Exception */ public function rowCount() { if (!$this->_stmt) { return false; } $num_rows = oci_num_rows($this->_stmt); if ($num_rows === false) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Statement/Oracle/Exception.php'; throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt)); } return $num_rows; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -