summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-09-30 21:24:45 +0200
committeradmin <devnull@localhost>2006-09-30 21:24:45 +0200
commit3dd978f680076be842bfcb5c9e2cbf35b926373b (patch)
treee4cd05724744ee70eb497118692581e750539548 /system/database/DB_driver.php
parent3ed8c51254a5b26d951fa675802fcf69adf9638e (diff)
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php101
1 files changed, 100 insertions, 1 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 275d51c53..5102cc74c 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -555,6 +555,95 @@ class CI_DB_driver {
// --------------------------------------------------------------------
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access public
+ * @return bool
+ */
+ function list_databases()
+ {
+ // Is there a cached result?
+ if (isset($this->cache['db_names']))
+ {
+ return $this->cache['db_names'];
+ }
+
+ $query = $this->query($this->_list_database());
+ $dbs = array();
+ if ($query->num_rows() > 0)
+ {
+ foreach ($query->result_array() as $row)
+ {
+ $dbs[] = current($row);
+ }
+ }
+
+ return $this->cache['db_names'] =& $dbs;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Returns an array of table names
+ *
+ * @access public
+ * @return array
+ */
+ function list_tables()
+ {
+ // Is there a cached result?
+ if (isset($this->cache['table_names']))
+ {
+ return $this->cache['table_names'];
+ }
+
+ if (FALSE === ($sql = $this->_list_tables()))
+ {
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_unsupported_function');
+ }
+ return FALSE;
+ }
+
+ $retval = array();
+ $query = $this->query($sql);
+
+ if ($query->num_rows() > 0)
+ {
+ foreach($query->result_array() as $row)
+ {
+ if (isset($row['TABLE_NAME']))
+ {
+ $retval[] = $row['TABLE_NAME'];
+ }
+ else
+ {
+ $retval[] = array_shift($row);
+ }
+ }
+ }
+
+ return $this->cache['table_names'] =& $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Determine if a particular table exists
+ * @access public
+ * @return boolean
+ */
+ function table_exists($table_name)
+ {
+ return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Fetch MySQL Field Names
*
@@ -562,7 +651,7 @@ class CI_DB_driver {
* @param string the table name
* @return array
*/
- function field_names($table = '')
+ function list_fields($table = '')
{
// Is there a cached result?
if (isset($this->cache['field_names'][$table]))
@@ -605,6 +694,16 @@ class CI_DB_driver {
return $this->cache['field_names'][$table] =& $retval;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * DEPRECATED - use list_fields()
+ */
+ function field_names($table = '')
+ {
+ return $this->list_fields($table);
+ }
// --------------------------------------------------------------------