summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/pdo
diff options
context:
space:
mode:
authorTimothy Warren <tim@timshomepage.net>2012-03-19 23:09:13 +0100
committerTimothy Warren <tim@timshomepage.net>2012-03-19 23:09:13 +0100
commit8c332e7f907e6af498f18fa1bf28e0a0c6e11448 (patch)
tree9412115b0349fe32d5a6b03af28cd405544b51a3 /system/database/drivers/pdo
parent142ca8e565b722b758b5ef88c888891d04da8700 (diff)
PDO driver access modifiers
Diffstat (limited to 'system/database/drivers/pdo')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php124
-rw-r--r--system/database/drivers/pdo/pdo_result.php25
-rw-r--r--system/database/drivers/pdo/pdo_utility.php12
3 files changed, 63 insertions, 98 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 658a3d5a0..727f097f8 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -42,28 +42,31 @@
*/
class CI_DB_pdo_driver extends CI_DB {
- var $dbdriver = 'pdo';
+ public $dbdriver = 'pdo';
// the character used to excape - not necessary for PDO
- var $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences
- var $_like_escape_str;
- var $_like_escape_chr;
+ protected $_like_escape_str;
+ protected $_like_escape_chr;
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * used for the count_all() and count_all_results() public functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword;
+ protected $_count_string = "SELECT COUNT(*) AS ";
+ protected $_random_keyword;
// need to track the pdo driver and options
- var $pdodriver;
- var $options = array();
+ protected $pdodriver;
+ protected $options = array();
- function __construct($params)
+ /**
+ * Pre-connection setup
+ */
+ public function __construct($params)
{
parent::__construct($params);
@@ -104,11 +107,10 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Connection String
*
- * @access private
* @param array
* @return void
*/
- function _connect_string($params)
+ protected function _connect_string($params)
{
if (strpos($this->hostname, ':'))
{
@@ -190,10 +192,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect()
+ protected function db_connect()
{
$this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
@@ -205,10 +206,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ protected function db_pconnect()
{
$this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
$this->options[PDO::ATTR_PERSISTENT] = TRUE;
@@ -221,10 +221,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* PDO connection
*
- * @access private called by the PDO driver class
* @return resource
*/
- function pdo_connect()
+ protected function pdo_connect()
{
// Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php
if ($this->pdodriver == 'mysql' && is_php('5.3.6'))
@@ -258,10 +257,9 @@ class CI_DB_pdo_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if ($this->db->db_debug)
{
@@ -276,10 +274,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ protected function db_select()
{
// Not needed for PDO
return TRUE;
@@ -304,11 +301,10 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return object
*/
- function _execute($sql)
+ protected function _execute($sql)
{
$sql = $this->_prep_query($sql);
@@ -333,11 +329,10 @@ class CI_DB_pdo_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
if ($this->pdodriver === 'pgsql')
{
@@ -347,7 +342,7 @@ class CI_DB_pdo_driver extends CI_DB {
elseif ($this->pdodriver === 'sqlite')
{
// Change the backtick(s) for SQLite
- $sql = str_replace('`', '', $sql);
+ $sql = str_replace('`', '"', $sql);
}
return $sql;
@@ -358,10 +353,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -387,10 +381,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -413,10 +406,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -439,12 +431,11 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @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))
{
@@ -483,10 +474,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
* @return integer
*/
- function affected_rows()
+ public function affected_rows()
{
return $this->affect_rows;
}
@@ -518,11 +508,10 @@ class CI_DB_pdo_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
@@ -550,20 +539,19 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
* @param boolean
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
if ($this->pdodriver == 'pgsql')
{
- // Analog function to show all tables in postgre
+ // Analog public function to show all tables in postgre
$sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'";
}
elseif ($this->pdodriver == 'sqlite')
{
- // Analog function to show all tables in sqlite
+ // Analog public function to show all tables in sqlite
$sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'";
}
else
@@ -586,11 +574,10 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ public function _list_columns($table = '')
{
return 'SHOW COLUMNS FROM '.$this->_from_tables($table);
}
@@ -602,25 +589,24 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
* @return object
*/
- function _field_data($table)
+ public function _field_data($table)
{
if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql')
{
- // Analog function for mysql and postgre
+ // Analog public function for mysql and postgre
return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1';
}
elseif ($this->pdodriver == 'oci')
{
- // Analog function for oci
+ // Analog public function for oci
return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1';
}
elseif ($this->pdodriver == 'sqlite')
{
- // Analog function for sqlite
+ // Analog public function for sqlite
return 'PRAGMA table_info('.$this->_from_tables($table).')';
}
@@ -661,13 +647,12 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Escape the SQL Identifiers
*
- * This function escapes column and table names
+ * This public function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ protected function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -704,14 +689,13 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* From Tables
*
- * This function implicitly groups FROM tables so there is no confusion
+ * This public function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
* @param type
* @return type
*/
- function _from_tables($tables)
+ public function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -728,13 +712,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* 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
*/
- function _insert($table, $keys, $values)
+ public function _insert($table, $keys, $values)
{
return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
@@ -746,13 +729,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* 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
*/
- function _insert_batch($table, $keys, $values)
+ public function _insert_batch($table, $keys, $values)
{
return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
@@ -764,7 +746,6 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -772,7 +753,7 @@ class CI_DB_pdo_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)
{
@@ -796,13 +777,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ public function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
$where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : '';
@@ -849,13 +829,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
* If the database does not support the truncate() command
- * This function maps to "DELETE FROM table"
+ * This public function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ public function _truncate($table)
{
return $this->_delete($table);
}
@@ -867,13 +846,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @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 = '';
@@ -902,13 +880,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ public function _limit($sql, $limit, $offset)
{
if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite')
{
@@ -930,11 +907,10 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ public function _close($conn_id)
{
$this->conn_id = null;
}
@@ -942,4 +918,4 @@ class CI_DB_pdo_driver extends CI_DB {
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 384b753da..330a2e677 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -51,10 +51,9 @@ class CI_DB_pdo_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
* @return integer
*/
- function num_rows()
+ public function num_rows()
{
if (empty($this->result_id) OR ! is_object($this->result_id))
{
@@ -74,10 +73,9 @@ class CI_DB_pdo_result extends CI_DB_result {
/**
* Fetch the result handler
*
- * @access public
* @return mixed
*/
- function result_assoc()
+ public function result_assoc()
{
// If the result already fetched before, use that one
if (count($this->result_array) > 0 OR $this->is_fetched)
@@ -116,10 +114,9 @@ class CI_DB_pdo_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
* @return integer
*/
- function num_fields()
+ public function num_fields()
{
return $this->result_id->columnCount();
}
@@ -131,10 +128,9 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
if ($this->db->db_debug)
{
@@ -151,10 +147,9 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$data = array();
@@ -224,7 +219,7 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* @return null
*/
- function free_result()
+ public function free_result()
{
if (is_object($this->result_id))
{
@@ -241,10 +236,9 @@ class CI_DB_pdo_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return FALSE;
}
@@ -256,10 +250,9 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return $this->result_id->fetch(PDO::FETCH_ASSOC);
}
@@ -274,7 +267,7 @@ class CI_DB_pdo_result extends CI_DB_result {
* @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return $this->result_id->fetchObject();
}
diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php
index c278c5172..2c12d7438 100644
--- a/system/database/drivers/pdo/pdo_utility.php
+++ b/system/database/drivers/pdo/pdo_utility.php
@@ -39,10 +39,9 @@ class CI_DB_pdo_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
* @return bool
*/
- function _list_databases()
+ protected function _list_databases()
{
// Not sure if PDO lets you list all databases...
if ($this->db->db_debug)
@@ -59,11 +58,10 @@ class CI_DB_pdo_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
* @return object
*/
- function _optimize_table($table)
+ protected function _optimize_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
@@ -80,11 +78,10 @@ class CI_DB_pdo_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
* @return object
*/
- function _repair_table($table)
+ protected function _repair_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
@@ -99,11 +96,10 @@ class CI_DB_pdo_utility extends CI_DB_utility {
/**
* PDO Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ protected function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');