summaryrefslogtreecommitdiffstats
path: root/system/database/DB_utility.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/DB_utility.php')
-rw-r--r--system/database/DB_utility.php214
1 files changed, 45 insertions, 169 deletions
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 950db7dfd..f98448adf 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -33,57 +33,69 @@ class CI_DB_utility {
$this->db =& $obj->db;
}
+ // --------------------------------------------------------------------
/**
- * Database Version Number. Returns a string containing the
- * version of the database being used
+ * Create database
*
* @access public
- * @return string
- */
- function version()
+ * @param string the database name
+ * @return bool
+ */
+ function create_database($db_name)
{
- if (FALSE === ($sql = $this->_version()))
+ $sql = $this->_create_database($db_name);
+
+ if (is_bool($sql))
{
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsupported_function');
- }
- return FALSE;
+ return $sql;
}
+
+ return $this->db->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @access public
+ * @param string the database name
+ * @return bool
+ */
+ function drop_database($db_name)
+ {
+ $sql = $this->_drop_database($db_name);
- if ($this->db->dbdriver == 'oci8')
- {
+ if (is_bool($sql))
+ {
return $sql;
}
- $query = $this->db->query($sql);
- $row = $query->row();
- return $row->ver;
+ return $this->db->query($sql);
}
// --------------------------------------------------------------------
/**
- * Primary
+ * List databases
*
- * Retrieves the primary key. It assumes that the row in the first
- * position is the primary key
- *
* @access public
- * @param string the table name
- * @return string
- */
- function primary($table = '')
+ * @return bool
+ */
+ function list_databases()
{
- $fields = $this->field_names($table);
-
- if ( ! is_array($fields))
+ $query = $this->db->query($this->_list_database());
+ $dbs = array();
+ if ($query->num_rows() > 0)
{
- return FALSE;
+ foreach ($query->result_array() as $row)
+ {
+ $dbs[] = current($row);
+ }
}
-
- return current($fields);
+
+ return $dbs;
}
// --------------------------------------------------------------------
@@ -94,9 +106,9 @@ class CI_DB_utility {
* @access public
* @return array
*/
- function tables()
+ function list_tables()
{
- if (FALSE === ($sql = $this->_show_tables()))
+ if (FALSE === ($sql = $this->_list_tables()))
{
if ($this->db->db_debug)
{
@@ -135,143 +147,7 @@ class CI_DB_utility {
*/
function table_exists($table_name)
{
- return ( ! in_array($this->db->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Fetch MySQL Field Names
- *
- * @access public
- * @param string the table name
- * @return array
- */
- function field_names($table = '')
- {
- if ($table == '')
- {
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_field_param_missing');
- }
- return FALSE;
- }
-
- if (FALSE === ($sql = $this->_show_columns($this->db->dbprefix.$table)))
- {
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsupported_function');
- }
- return FALSE;
- }
-
- $query = $this->db->query($sql);
-
- $retval = array();
- foreach($query->result_array() as $row)
- {
- if (isset($row['COLUMN_NAME']))
- {
- $retval[] = $row['COLUMN_NAME'];
- }
- else
- {
- $retval[] = current($row);
- }
- }
-
- return $retval;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Returns an object with field data
- *
- * @access public
- * @param string the table name
- * @return object
- */
- function field_data($table = '')
- {
- if ($table == '')
- {
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_field_param_missing');
- }
- return FALSE;
- }
-
- $query = $this->db->query($this->_field_data($this->db->dbprefix.$table));
- return $query->field_data();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Create database
- *
- * @access public
- * @param string the database name
- * @return bool
- */
- function create_database($db_name)
- {
- $sql = $this->_create_database($db_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Drop database
- *
- * @access public
- * @param string the database name
- * @return bool
- */
- function drop_database($db_name)
- {
- $sql = $this->_drop_database($db_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * List databases
- *
- * @access public
- * @return bool
- */
- function list_databases()
- {
- $query = $this->db->query($this->_list_database());
- $dbs = array();
- if ($query->num_rows() > 0)
- {
- foreach ($query->result_array() as $row)
- {
- $dbs[] = current($row);
- }
- }
-
- return $dbs;
+ return ( ! in_array($this->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE;
}
// --------------------------------------------------------------------