summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2011-10-07 20:04:58 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-10-27 01:01:42 +0200
commit3e1df1abe203db8c07ffbd9096aec77c458b80d5 (patch)
tree5d63e4acf3fa89c67140f2236aafd9222739c34e /system
parent75b1f3991013c17cacac18e47879c483fe1cf542 (diff)
Cleanup and migrate oci8_driver and oci8_result from deprecated PHP4 to PHP5 style functions
Diffstat (limited to 'system')
-rw-r--r--system/database/drivers/oci8/oci8_driver.php144
-rw-r--r--system/database/drivers/oci8/oci8_result.php94
2 files changed, 120 insertions, 118 deletions
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 14df104ff..985466a79 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -35,8 +35,6 @@
* This is a modification of the DB_driver class to
* permit access to oracle databases
*
- * NOTE: this uses the PHP 4 oci methods
- *
* @author Kelly McArdle
*
*/
@@ -77,9 +75,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
- function db_connect()
+ public function db_connect()
{
- return @ocilogon($this->username, $this->password, $this->hostname);
+ return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set);
}
// --------------------------------------------------------------------
@@ -90,9 +88,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return @ociplogon($this->username, $this->password, $this->hostname);
+ return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set);
}
// --------------------------------------------------------------------
@@ -106,9 +104,10 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
// not implemented in oracle
+ return;
}
// --------------------------------------------------------------------
@@ -119,8 +118,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
+ // Not in Oracle - schemas are actually usernames
return TRUE;
}
@@ -134,7 +134,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string
* @return resource
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
// @todo - add support if needed
return TRUE;
@@ -148,9 +148,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return string
*/
- function _version()
+ public function _version()
{
- return ociserverversion($this->conn_id);
+ return oci_server_version($this->conn_id);
}
// --------------------------------------------------------------------
@@ -158,18 +158,18 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
+ * @access public called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ public function _execute($sql)
{
// oracle must parse the query before it is run. All of the actions with
// the query are based on the statement id returned by ociparse
$this->stmt_id = FALSE;
$this->_set_stmt_id($sql);
- ocisetprefetch($this->stmt_id, 1000);
- return @ociexecute($this->stmt_id, $this->_commit);
+ oci_set_prefetch($this->stmt_id, 1000);
+ return @oci_execute($this->stmt_id, $this->_commit);
}
/**
@@ -179,11 +179,11 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string an SQL query
* @return none
*/
- function _set_stmt_id($sql)
+ private function _set_stmt_id($sql)
{
if ( ! is_resource($this->stmt_id))
{
- $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql));
+ $this->stmt_id = oci_parse($this->conn_id, $this->_prep_query($sql));
}
}
@@ -198,7 +198,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ private function _prep_query($sql)
{
return $sql;
}
@@ -211,9 +211,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return cursor id
*/
- function get_cursor()
+ public function get_cursor()
{
- $this->curs_id = ocinewcursor($this->conn_id);
+ $this->curs_id = oci_new_cursor($this->conn_id);
return $this->curs_id;
}
@@ -237,7 +237,7 @@ class CI_DB_oci8_driver extends CI_DB {
* type yes the type of the parameter
* length yes the max size of the parameter
*/
- function stored_procedure($package, $procedure, $params)
+ public function stored_procedure($package, $procedure, $params)
{
if ($package == '' OR $procedure == '' OR ! is_array($params))
{
@@ -257,7 +257,7 @@ class CI_DB_oci8_driver extends CI_DB {
{
$sql .= $param['name'] . ",";
- if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR))
+ if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR))
{
$have_cursor = TRUE;
}
@@ -278,7 +278,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private
* @return none
*/
- function _bind_params($params)
+ private function _bind_params($params)
{
if ( ! is_array($params) OR ! is_resource($this->stmt_id))
{
@@ -295,7 +295,7 @@ class CI_DB_oci8_driver extends CI_DB {
}
}
- ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
+ oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
}
}
@@ -307,7 +307,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -337,7 +337,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -350,7 +350,7 @@ class CI_DB_oci8_driver extends CI_DB {
return TRUE;
}
- $ret = OCIcommit($this->conn_id);
+ $ret = oci_commit($this->conn_id);
$this->_commit = OCI_COMMIT_ON_SUCCESS;
return $ret;
}
@@ -363,7 +363,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -376,7 +376,7 @@ class CI_DB_oci8_driver extends CI_DB {
return TRUE;
}
- $ret = OCIrollback($this->conn_id);
+ $ret = oci_rollback($this->conn_id);
$this->_commit = OCI_COMMIT_ON_SUCCESS;
return $ret;
}
@@ -391,7 +391,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -424,9 +424,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return integer
*/
- function affected_rows()
+ public function affected_rows()
{
- return @ocirowcount($this->stmt_id);
+ return @oci_num_rows($this->stmt_id);
}
// --------------------------------------------------------------------
@@ -437,7 +437,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return integer
*/
- function insert_id()
+ public function insert_id()
{
// not supported in oracle
return $this->display_error('db_unsupported_function');
@@ -455,7 +455,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
@@ -480,11 +480,11 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
+ * @access public
* @param boolean
- * @return string
+ * @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ public function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT TABLE_NAME FROM ALL_TABLES";
@@ -507,7 +507,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ public function _list_columns($table = '')
{
return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'";
}
@@ -523,7 +523,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string the table name
* @return object
*/
- function _field_data($table)
+ public function _field_data($table)
{
return "SELECT * FROM ".$table." where rownum = 1";
}
@@ -533,12 +533,13 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* The error message string
*
- * @access private
+ * @access public
* @return string
*/
- function _error_message()
+ public function _error_message()
{
- $error = ocierror($this->conn_id);
+ // If the error was during connection, no conn_id should be passed
+ $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
return $error['message'];
}
@@ -547,12 +548,13 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* The error message number
*
- * @access private
+ * @access public
* @return integer
*/
- function _error_number()
+ public function _error_number()
{
- $error = ocierror($this->conn_id);
+ // Same as _error_message()
+ $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
return $error['code'];
}
@@ -563,11 +565,11 @@ class CI_DB_oci8_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
+ * @access public
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -610,7 +612,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param type
* @return type
*/
- function _from_tables($tables)
+ public function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -633,9 +635,37 @@ class CI_DB_oci8_driver extends CI_DB {
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ public function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert_batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data
+ *
+ * @access public
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
+ */
+ public function _insert_batch($table, $keys, $values)
+ {
+ $keys = implode(', ', $keys);
+ $sql = "INSERT ALL\n";
+
+ for ($i = 0, $c = count($values); $i < $c; $i++)
+ {
+ $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n";
+ }
+
+ $sql .= 'SELECT * FROM dual';
+
+ return $sql;
}
// --------------------------------------------------------------------
@@ -653,7 +683,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ public function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
@@ -686,7 +716,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string the table name
* @return string
*/
- function _truncate($table)
+ public function _truncate($table)
{
return "TRUNCATE TABLE ".$table;
}
@@ -704,7 +734,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ public function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -738,7 +768,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param integer the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ public function _limit($sql, $limit, $offset)
{
$limit = $offset + $limit;
$newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)";
@@ -763,9 +793,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @param resource
* @return void
*/
- function _close($conn_id)
+ public function _close($conn_id)
{
- @ocilogoff($conn_id);
+ @oci_close($conn_id);
}
@@ -774,4 +804,4 @@ class CI_DB_oci8_driver extends CI_DB {
/* End of file oci8_driver.php */
-/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/oci8/oci8_driver.php */
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index 88531b436..7de1153ba 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -40,14 +40,17 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return integer
*/
- function num_rows()
+ public function num_rows()
{
- $rowcount = count($this->result_array());
- @ociexecute($this->stmt_id);
-
- if ($this->curs_id)
+ if ($this->num_rows === 0 && count($this->result_array()) > 0)
{
- @ociexecute($this->curs_id);
+ $this->num_rows = count($this->result_array());
+ @oci_execute($this->stmt_id);
+
+ if ($this->curs_id)
+ {
+ @oci_execute($this->curs_id);
+ }
}
return $rowcount;
@@ -61,9 +64,9 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return integer
*/
- function num_fields()
+ public function num_fields()
{
- $count = @ocinumcols($this->stmt_id);
+ $count = @oci_num_fields($this->stmt_id);
// if we used a limit we subtract it
if ($this->limit_used)
@@ -84,13 +87,12 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- $fieldCount = $this->num_fields();
- for ($c = 1; $c <= $fieldCount; $c++)
+ for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
{
- $field_names[] = ocicolumnname($this->stmt_id, $c);
+ $field_names[] = oci_field_name($this->stmt_id, $c);
}
return $field_names;
}
@@ -105,16 +107,15 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- $fieldCount = $this->num_fields();
- for ($c = 1; $c <= $fieldCount; $c++)
+ for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
{
- $F = new stdClass();
- $F->name = ocicolumnname($this->stmt_id, $c);
- $F->type = ocicolumntype($this->stmt_id, $c);
- $F->max_length = ocicolumnsize($this->stmt_id, $c);
+ $F = new stdClass();
+ $F->name = oci_field_name($this->stmt_id, $c);
+ $F->type = oci_field_type($this->stmt_id, $c);
+ $F->max_length = oci_field_size($this->stmt_id, $c);
$retval[] = $F;
}
@@ -129,11 +130,11 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* @return null
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
- ocifreestatement($this->result_id);
+ oci_free_statement($this->result_id);
$this->result_id = FALSE;
}
}
@@ -145,14 +146,13 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
+ * @access public
* @return array
*/
- function _fetch_assoc(&$row)
+ public function _fetch_assoc()
{
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
-
- return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
+ return oci_fetch_assoc($id);
}
// --------------------------------------------------------------------
@@ -162,41 +162,13 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
+ * @access public
* @return object
*/
- function _fetch_object()
+ public function _fetch_object()
{
- $result = array();
-
- // If PHP 5 is being used we can fetch an result object
- if (function_exists('oci_fetch_object'))
- {
- $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
-
- return @oci_fetch_object($id);
- }
-
- // If PHP 4 is being used we have to build our own result
- foreach ($this->result_array() as $key => $val)
- {
- $obj = new stdClass();
- if (is_array($val))
- {
- foreach ($val as $k => $v)
- {
- $obj->$k = $v;
- }
- }
- else
- {
- $obj->$key = $val;
- }
-
- $result[] = $obj;
- }
-
- return $result;
+ $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
+ return @oci_fetch_object($id);
}
// --------------------------------------------------------------------
@@ -207,7 +179,7 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return array
*/
- function result_array()
+ public function result_array()
{
if (count($this->result_array) > 0)
{
@@ -217,7 +189,7 @@ class CI_DB_oci8_result extends CI_DB_result {
// oracle's fetch functions do not return arrays.
// The information is returned in reference parameters
$row = NULL;
- while ($this->_fetch_assoc($row))
+ while ($row = $this->_fetch_assoc())
{
$this->result_array[] = $row;
}
@@ -234,10 +206,10 @@ class CI_DB_oci8_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
+ * @access public
* @return array
*/
- function _data_seek($n = 0)
+ public function _data_seek($n = 0)
{
return FALSE; // Not needed
}