Skip to content

CI_DB_pdo_oci_driver

Mathieu Nayrolles edited this page Jan 20, 2016 · 1 revision

CI_DB_pdo_oci_driver

PDO Oracle Database Adapter Class

Note: _DB is an extender class that the app controller creates dynamically based on whether the query builder class is being used or not.

Properties

$subdriver

public string $subdriver

Sub-driver

  • Visibility: public

$_reserved_identifiers

protected array<mixed,string> $_reserved_identifiers = array('*')

List of reserved identifiers

Identifiers that must NOT be escaped.

  • Visibility: protected

$_random_keyword

protected array $_random_keyword = array('RAND()', 'RAND(%d)')

ORDER BY random keyword

  • Visibility: protected

$_count_string

protected string $_count_string = 'SELECT COUNT(*) AS '

COUNT string

  • Visibility: protected

$dbdriver

public string $dbdriver = 'mysqli'

Database driver

  • Visibility: public

$options

public array $options = array()

PDO Options

  • Visibility: public

$dsn

public string $dsn

Data Source Name / Connect string

  • Visibility: public

$username

public string $username

Username

  • Visibility: public

$password

public string $password

Password

  • Visibility: public

$hostname

public string $hostname

Hostname

  • Visibility: public

$database

public string $database

Database name

  • Visibility: public

$dbprefix

public string $dbprefix = ''

Table prefix

  • Visibility: public

$char_set

public string $char_set = 'utf8'

Character set

  • Visibility: public

$dbcollat

public string $dbcollat = 'utf8_general_ci'

Collation

  • Visibility: public

$encrypt

public mixed $encrypt = FALSE

Encryption flag/data

  • Visibility: public

$swap_pre

public string $swap_pre = ''

Swap Prefix

  • Visibility: public

$port

public integer $port = ''

Database port

  • Visibility: public

$pconnect

public boolean $pconnect = FALSE

Persistent connection flag

  • Visibility: public

$conn_id

public object $conn_id = FALSE

Connection ID

  • Visibility: public

$result_id

public object $result_id = FALSE

Result ID

  • Visibility: public

$db_debug

public boolean $db_debug = FALSE

Debug flag

Whether to display error messages.

  • Visibility: public

$benchmark

public integer $benchmark

Benchmark time

  • Visibility: public

$query_count

public integer $query_count

Executed queries count

  • Visibility: public

$bind_marker

public string $bind_marker = '?'

Bind marker

Character used to identify values in a prepared statement.

  • Visibility: public

$save_queries

public boolean $save_queries = TRUE

Save queries flag

Whether to keep an in-memory history of queries for debugging purposes.

  • Visibility: public

$queries

public array<mixed,string> $queries = array()

Queries list

  • Visibility: public

$query_times

public array $query_times = array()

Query times

A list of times that queries took to execute.

  • Visibility: public

$data_cache

public array $data_cache = array()

Data cache

An internal generic value cache.

  • Visibility: public

$trans_enabled

public boolean $trans_enabled = TRUE

Transaction enabled flag

  • Visibility: public

$trans_strict

public boolean $trans_strict = TRUE

Strict transaction mode flag

  • Visibility: public

$_trans_depth

protected integer $_trans_depth

Transaction depth level

  • Visibility: protected

$_trans_status

protected boolean $_trans_status = TRUE

Transaction status flag

Used with transactions to determine if a rollback should occur.

  • Visibility: protected

$_trans_failure

protected boolean $_trans_failure = FALSE

Transaction failure flag

Used with transactions to determine if a transaction has failed.

  • Visibility: protected

$cache_on

public boolean $cache_on = FALSE

Cache On flag

  • Visibility: public

$cachedir

public boolean $cachedir = ''

Cache directory path

  • Visibility: public

$cache_autodel

public boolean $cache_autodel = FALSE

Cache auto-delete flag

  • Visibility: public

$CACHE

public object $CACHE

DB Cache object

  • Visibility: public

$_protect_identifiers

protected boolean $_protect_identifiers = TRUE

Protect identifiers flag

  • Visibility: protected

$_escape_char

protected string $_escape_char = '"'

Identifier escape character

  • Visibility: protected

$_like_escape_str

protected string $_like_escape_str = " ESCAPE '%s' "

ESCAPE statement string

  • Visibility: protected

$_like_escape_chr

protected string $_like_escape_chr = '!'

ESCAPE character

  • Visibility: protected

Methods

__construct

void CI_DB_pdo_driver::__construct(array $params)

Class constructor

Arguments

  • $params array

_list_tables

string CI_DB_pdo_oci_driver::_list_tables(boolean $prefix_limit)

Show table query

Generates a platform-specific query string so that the table names can be fetched

  • Visibility: protected

Arguments

  • $prefix_limit boolean

_list_columns

string CI_DB_pdo_oci_driver::_list_columns(string $table)

Show column query

Generates a platform-specific query string so that the column names can be fetched

  • Visibility: protected

Arguments

  • $table string

field_data

array CI_DB_pdo_driver::field_data(string $table)

Returns an object with field data

Arguments

  • $table string - <p>the table name</p>

_insert_batch

string CI_DB_pdo_oci_driver::_insert_batch(string $table, array $keys, array $values)

Insert batch statement

  • Visibility: protected

Arguments

  • $table string - <p>Table name</p>
  • $keys array - <p>INSERT keys</p>
  • $values array - <p>INSERT values</p>

_delete

string CI_DB_pdo_oci_driver::_delete(string $table)

Delete statement

Generates a platform-specific delete string from the supplied data

  • Visibility: protected

Arguments

  • $table string

_limit

string CI_DB_pdo_oci_driver::_limit(string $sql)

LIMIT

Generates a platform-specific LIMIT clause

  • Visibility: protected

Arguments

  • $sql string - <p>SQL Query</p>

db_connect

mixed CI_DB_pdo_driver::db_connect()

DB connect

This is just a dummy method that all drivers will override.

version

string CI_DB_pdo_driver::version()

Database version number

Returns a string containing the version of the database being used. Most drivers will override this method.

_execute

mixed CI_DB_pdo_driver::_execute(string $sql)

Execute the query

Arguments

  • $sql string - <p>SQL query</p>

trans_begin

boolean CI_DB_pdo_driver::trans_begin(boolean $test_mode)

Begin Transaction

Arguments

  • $test_mode boolean

trans_commit

boolean CI_DB_pdo_driver::trans_commit()

Commit Transaction

trans_rollback

boolean CI_DB_pdo_driver::trans_rollback()

Rollback Transaction

_escape_str

string CI_DB_pdo_driver::_escape_str($str)

Platform-dependant string escape

Arguments

  • $str mixed

affected_rows

integer CI_DB_pdo_driver::affected_rows()

Affected Rows

insert_id

integer CI_DB_pdo_driver::insert_id(string $name)

Insert ID

Arguments

  • $name string

_field_data

string CI_DB_pdo_driver::_field_data(string $table)

Field data query

Generates a platform-specific query so that the column data can be retrieved

Arguments

  • $table string

error

array CI_DB_pdo_driver::error()

Error

Returns an array containing code and message of the last database error that has occured.

_update_batch

string CI_DB_pdo_driver::_update_batch(string $table, array $values, string $index)

Update_Batch statement

Generates a platform-specific batch update string from the supplied data

Arguments

  • $table string - <p>Table name</p>
  • $values array - <p>Update data</p>
  • $index string - <p>WHERE key</p>

_truncate

string CI_DB_pdo_driver::_truncate(string $table)

Truncate statement

Generates a platform-specific truncate string from the supplied data

If the database does not support the TRUNCATE statement, then this method maps to 'DELETE FROM table'

Arguments

  • $table string

initialize

boolean CI_DB_pdo_driver::initialize()

Initialize Database Settings

db_pconnect

mixed CI_DB_pdo_driver::db_pconnect()

Persistent database connection

reconnect

void CI_DB_pdo_driver::reconnect()

Reconnect

Keep / reestablish the db connection if no queries have been sent for a length of time exceeding the server's idle timeout.

This is just a dummy method to allow drivers without such functionality to not declare it, while others will override it.

db_select

boolean CI_DB_pdo_driver::db_select()

Select database

This is just a dummy method to allow drivers without such functionality to not declare it, while others will override it.

db_set_charset

boolean CI_DB_pdo_driver::db_set_charset($charset)

Set client character set

Arguments

  • $charset mixed

platform

string CI_DB_pdo_driver::platform()

The name of the platform in use (mysql, mssql, etc.

..)

_version

string CI_DB_pdo_driver::_version()

Version number query string

query

mixed CI_DB_pdo_driver::query(string $sql, array $binds, boolean $return_object)

Execute the query

Accepts an SQL string as input and returns a result object upon successful execution of a "read" type query. Returns boolean TRUE upon successful execution of a "write" type query. Returns boolean FALSE upon failure, and if the $db_debug variable is set to TRUE will raise an error.

Arguments

  • $sql string
  • $binds array - <p>= FALSE An array of binding data</p>
  • $return_object boolean - <p>= NULL</p>

load_rdriver

string CI_DB_pdo_driver::load_rdriver()

Load the result drivers

simple_query

mixed CI_DB_pdo_driver::simple_query($sql)

Simple Query This is a simplified version of the query() function. Internally we only use it when running transaction commands since they do not require all the features of the main query() function.

Arguments

  • $sql mixed

trans_off

void CI_DB_pdo_driver::trans_off()

Disable Transactions This permits transactions to be disabled at run-time.

trans_strict

void CI_DB_pdo_driver::trans_strict(boolean $mode)

Enable/disable Transaction Strict Mode When strict mode is enabled, if you are running multiple groups of transactions, if one group fails all groups will be rolled back.

If strict mode is disabled, each group is treated autonomously, meaning a failure of one group will not affect any others

Arguments

  • $mode boolean - <p>= TRUE</p>

trans_start

void CI_DB_pdo_driver::trans_start(boolean $test_mode)

Start Transaction

Arguments

  • $test_mode boolean - <p>= FALSE</p>

trans_complete

boolean CI_DB_pdo_driver::trans_complete()

Complete Transaction

trans_status

boolean CI_DB_pdo_driver::trans_status()

Lets you retrieve the transaction flag to determine if it has failed

compile_binds

string CI_DB_pdo_driver::compile_binds($sql, $binds)

Compile Bindings

Arguments

  • $sql mixed
  • $binds mixed

is_write_type

boolean CI_DB_pdo_driver::is_write_type($sql)

Determines if a query is a "write" type.

Arguments

  • $sql mixed

elapsed_time

string CI_DB_pdo_driver::elapsed_time($decimals)

Calculate the aggregate query elapsed time

Arguments

  • $decimals mixed

total_queries

integer CI_DB_pdo_driver::total_queries()

Returns the total number of queries

last_query

string CI_DB_pdo_driver::last_query()

Returns the last query that was executed

escape

mixed CI_DB_pdo_driver::escape($str)

"Smart" Escape String

Escapes data based on type Sets boolean and null types

Arguments

  • $str mixed

escape_str

string CI_DB_pdo_driver::escape_str(string|array<mixed,string> $str, boolean $like)

Escape String

Arguments

  • $str string|array<mixed,string> - <p>Input string</p>
  • $like boolean - <p>Whether or not the string will be used in a LIKE condition</p>

escape_like_str

mixed CI_DB_pdo_driver::escape_like_str($str)

Escape LIKE String

Calls the individual driver for platform specific escaping for LIKE conditions

Arguments

  • $str mixed

primary

string CI_DB_pdo_driver::primary(string $table)

Primary

Retrieves the primary key. It assumes that the row in the first position is the primary key

Arguments

  • $table string - <p>Table name</p>

count_all

integer CI_DB_pdo_driver::count_all($table)

"Count All" query

Generates a platform-specific query string that counts all records in the specified database

Arguments

  • $table mixed

list_tables

array CI_DB_pdo_driver::list_tables(string $constrain_by_prefix)

Returns an array of table names

Arguments

  • $constrain_by_prefix string - <p>= FALSE</p>

table_exists

boolean CI_DB_pdo_driver::table_exists(string $table_name)

Determine if a particular table exists

Arguments

  • $table_name string

list_fields

array CI_DB_pdo_driver::list_fields(string $table)

Fetch Field Names

Arguments

  • $table string - <p>Table name</p>

field_exists

boolean CI_DB_pdo_driver::field_exists($field_name, $table_name)

Determine if a particular field exists

Arguments

  • $field_name mixed
  • $table_name mixed

escape_identifiers

mixed CI_DB_pdo_driver::escape_identifiers($item)

Escape the SQL Identifiers

This function escapes column and table names

Arguments

  • $item mixed

insert_string

string CI_DB_pdo_driver::insert_string($table, $data)

Generate an insert string

Arguments

  • $table mixed
  • $data mixed

_insert

string CI_DB_pdo_driver::_insert($table, $keys, $values)

Insert statement

Generates a platform-specific insert string from the supplied data

Arguments

  • $table mixed
  • $keys mixed
  • $values mixed

update_string

string CI_DB_pdo_driver::update_string($table, $data, $where)

Generate an update string

Arguments

  • $table mixed
  • $data mixed
  • $where mixed

_update

string CI_DB_pdo_driver::_update($table, $values)

Update statement

Generates a platform-specific update string from the supplied data

Arguments

  • $table mixed
  • $values mixed

_has_operator

boolean CI_DB_pdo_driver::_has_operator($str)

Tests whether the string has an SQL operator

Arguments

  • $str mixed

_get_operator

string CI_DB_pdo_driver::_get_operator($str)

Returns the SQL string operator

Arguments

  • $str mixed

call_function

mixed CI_DB_pdo_driver::call_function(string $function)

Enables a native PHP function to be run, using a platform agnostic wrapper.

Arguments

  • $function string - <p>Function name</p>

cache_set_path

void CI_DB_pdo_driver::cache_set_path($path)

Set Cache Directory Path

Arguments

  • $path mixed

cache_on

boolean CI_DB_pdo_driver::cache_on()

Enable Query Caching

cache_off

boolean CI_DB_pdo_driver::cache_off()

Disable Query Caching

cache_delete

boolean CI_DB_pdo_driver::cache_delete(string $segment_one, string $segment_two)

Delete the cache files associated with a particular URI

Arguments

  • $segment_one string - <p>= ''</p>
  • $segment_two string - <p>= ''</p>

cache_delete_all

boolean CI_DB_pdo_driver::cache_delete_all()

Delete All cache files

_cache_init

boolean CI_DB_pdo_driver::_cache_init()

Initialize the Cache Class

close

void CI_DB_pdo_driver::close()

Close DB Connection

_close

void CI_DB_pdo_driver::_close()

Close DB Connection

This method would be overridden by most of the drivers.

display_error

string CI_DB_pdo_driver::display_error($error, $swap, $native)

Display an error message

Arguments

  • $error mixed
  • $swap mixed
  • $native mixed

protect_identifiers

string CI_DB_pdo_driver::protect_identifiers($item, $prefix_single, $protect_identifiers, $field_exists)

Protect Identifiers

This function is used extensively by the Query Builder class, and by a couple functions in this class. It takes a column or table name (optionally with an alias) and inserts the table prefix onto it. Some logic is necessary in order to deal with column names that include the path. Consider a query like this:

SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table

Or a query with aliasing:

SELECT m.member_id, m.member_name FROM members AS m

Since the column name can include up to four segments (host, DB, table, column) or also have an alias prefix, we need to do a bit of work to figure this out and insert the table prefix (if it exists) in the proper position, and escape only the correct identifiers.

Arguments

  • $item mixed
  • $prefix_single mixed
  • $protect_identifiers mixed
  • $field_exists mixed

_reset_select

void CI_DB_pdo_driver::_reset_select()

Dummy method that allows Query Builder class to be disabled and keep count_all() working.

Clone this wiki locally