summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_driver.php101
-rw-r--r--system/database/DB_utility.php310
-rw-r--r--system/database/drivers/mssql/mssql_driver.php28
-rw-r--r--system/database/drivers/mssql/mssql_utility.php28
-rw-r--r--system/database/drivers/mysql/mysql_driver.php28
-rw-r--r--system/database/drivers/mysql/mysql_utility.php95
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php30
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php28
-rw-r--r--system/database/drivers/oci8/oci8_driver.php28
-rw-r--r--system/database/drivers/oci8/oci8_utility.php28
-rw-r--r--system/database/drivers/odbc/odbc_driver.php33
-rw-r--r--system/database/drivers/odbc/odbc_utility.php53
-rw-r--r--system/database/drivers/postgre/postgre_driver.php28
-rw-r--r--system/database/drivers/postgre/postgre_utility.php28
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php39
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php46
-rw-r--r--system/language/english/db_lang.php3
-rw-r--r--user_guide/database/fields.html16
-rw-r--r--user_guide/database/index.html1
-rw-r--r--user_guide/database/table_data.html6
-rw-r--r--user_guide/database/utilities.html32
21 files changed, 578 insertions, 411 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);
+ }
// --------------------------------------------------------------------
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index ff9407ebd..dc56d6524 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -87,93 +87,6 @@ class CI_DB_utility {
// --------------------------------------------------------------------
/**
- * 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->db->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->db_debug)
- {
- return $this->db->display_error('db_unsupported_function');
- }
- return FALSE;
- }
-
- $retval = array();
- $query = $this->db->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->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Optimize Table
*
* @access public
@@ -372,12 +285,231 @@ class CI_DB_utility {
* @access public
* @return void
*/
- function export()
+ function backup($params = array())
{
- // The individual driver overloads this method
+ // If the parameters have not been submitted as an
+ // array then we know that it is simply the table
+ // name, which is a valid short cut.
+ if (is_string($params))
+ {
+ $params = array('tables' => $params);
+ }
+
+ // ------------------------------------------------------
+
+ // Set up our default preferences
+ $prefs = array(
+ 'tables' => array(),
+ 'ignore' => array(),
+ 'format' => 'gzip', // gzip, zip, txt
+ 'action' => 'download', // download, archive, echo, return
+ 'filename' => '',
+ 'filepath' => '',
+ 'add_drop' => TRUE,
+ 'add_insert' => TRUE,
+ 'newline' => "\n"
+ );
+
+ // Did the user submit any preferences? If so set them....
+ if (count($params) > 0)
+ {
+ foreach ($prefs as $key => $val)
+ {
+ if (isset($params[$key]))
+ {
+ $prefs[$key] = $params[$key];
+ }
+ }
+ }
+
+ // ------------------------------------------------------
+
+ // Are we backing up a complete database or individual tables?
+ // If no table names were submitted we'll fetch the entire table list
+ if (count($prefs['tables']) == 0)
+ {
+ $prefs['tables'] = $this->list_tables();
+ }
+
+ // ------------------------------------------------------
+
+ // Validate the format
+ if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
+ {
+ $prefs['format'] = 'txt';
+ }
+
+ // ------------------------------------------------------
+
+ // Is the encoder supported? If not, we'll either issue an
+ // error or use plain text depending on the debug settings
+ if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode'))
+ OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress')))
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_compression');
+ }
+
+ $prefs['format'] = 'txt';
+ }
+
+ // ------------------------------------------------------
+
+ // Set the filename if not provided
+ if ($prefs['filename'] == '')
+ {
+ $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database;
+ $prefs['filename'] .= '_'.date('Y-m-d_H-i', time());
+ }
+
+ // ------------------------------------------------------
+
+ // If we are archiving the export, does this filepath exist
+ // and resolve to a writable directory
+ if ($prefs['action'] == 'archive')
+ {
+ if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath']))
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_filepath_error');
+ }
+
+ $prefs['action'] = 'download';
+ }
+ }
+
+ // ------------------------------------------------------
+
+ // Are we returning the backup data? If so, we're done...
+ if ($prefs['action'] == 'return')
+ {
+ return $this->_backup($prefs);
+ }
+
+ // ------------------------------------------------------
+
+ // Are we echoing the backup? If so, format the data and spit it at the screen...
+ if ($prefs['action'] == 'echo')
+ {
+ echo '<pre>';
+ echo htmlspecialchars($this->_backup($prefs));
+ echo '</pre>';
+
+ return TRUE;
+ }
+
+ // ------------------------------------------------------
+
+ // Are we archiving the data to the server?
+ if ($prefs['action'] == 'archive')
+ {
+ // Make sure the filepath has a trailing slash
+ if (ereg("/$", $prefs['filepath']) === FALSE)
+ {
+ $prefs['filepath'] .= '/';
+ }
+
+ // Assemble the path and tack on the file extension
+ $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql');
+ $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']];
+
+ // Load the file helper
+ $obj =& get_instance();
+ $obj->load->helper('file');
+
+ // Write the file based on type
+ switch ($prefs['format'])
+ {
+ case 'gzip' :
+ write_file($path, gzencode($this->_backup($prefs)));
+ return TRUE;
+ break;
+ case 'txt' :
+ write_file($path, $this->_backup($prefs));
+ return TRUE;
+ break;
+ default :
+ require BASEPATH.'libraries/Zip.php';
+ $zip = new Zip;
+ $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql');
+ write_file($path, $zip->output_zipfile());
+ return TRUE;
+ break;
+ }
+
+ }
+
+ // ------------------------------------------------------
+
+ // Set the mime type used in the server header
+ switch ($prefs['format'])
+ {
+ case 'zip' : $mime = 'application/x-zip';
+ break;
+ case 'gzip' : $mime = 'application/x-gzip';
+ break;
+ default :
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA"))
+ {
+ $mime = 'application/octetstream';
+ }
+ else
+ {
+ $mime = 'application/octet-stream';
+ }
+ break;
+ }
+
+ // Grab the super object
+ $obj =& get_instance();
+
+ // Remap the file extensions
+ $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql');
+
+ // Send headers
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
+ {
+ $obj->output->set_header('Content-Type: '.$mime);
+ $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"');
+ $obj->output->set_header('Expires: 0');
+ $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ $obj->output->set_header('Pragma: public');
+ }
+ else
+ {
+ $obj->output->set_header('Content-Type: '.$mime);
+ $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"');
+ $obj->output->set_header('Expires: 0');
+ $obj->output->set_header('Pragma: no-cache');
+ }
+
+
+ // Write the file based on type
+ switch ($prefs['format'])
+ {
+ case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs)));
+ break;
+ case 'txt' : $obj->output->set_output($this->_backup($prefs));
+ break;
+ default :
+ require BASEPATH.'libraries/Zip.php';
+
+ $zip = new Zip;
+ $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql');
+ $obj->output->set_output($zip->output_zipfile());
+ break;
+ }
+
+ return TRUE;
}
+
+
+
+
}
?> \ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 3f5e53345..8b82ee314 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -262,6 +262,34 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * List databases
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* List columnn query
*
* Generates a platform-specific query string so that the column names can be fetched
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index 96b8180b8..ad13167cd 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -54,34 +54,6 @@ class CI_DB_mssql_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases
- }
-
- // --------------------------------------------------------------------
-
- /**
- * List table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* @access private
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 792e023a8..ecab648d4 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -292,6 +292,34 @@ class CI_DB_mysql_driver extends CI_DB {
$row = $query->row();
return $row->numrows;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ return "SHOW DATABASES";
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SHOW TABLES FROM `".$this->database."`";
+ }
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index f43299382..a81c915f6 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -53,34 +53,6 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- return "SHOW DATABASES";
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SHOW TABLES FROM `".$this->db->database."`";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* @access private
@@ -132,50 +104,22 @@ class CI_DB_mysql_utility extends CI_DB_utility {
* @param array Any preferences
* @return mixed
*/
- function _export($params = array())
+ function _backup($params = array())
{
- // Set up our default preferences
- $prefs = array(
- 'tables' => array(),
- 'ignore' => array(),
- 'format' => 'gzip',
- 'action' => 'download', // download, archive, echo, return
- 'filename' => date('Y-m-d-H:i', time()),
- 'filepath' => '',
- 'add_drop' => TRUE,
- 'add_insert' => TRUE,
- 'newline' => "\n"
- );
-
- // Did the user submit any preference overrides? If so set them....
- if (count($params) > 0)
+ if (count($params) == 0)
{
- foreach ($prefs as $key => $val)
- {
- if (isset($params[$key]))
- {
- $prefs[$key] = $params[$key];
- }
- }
+ return FALSE;
}
// Extract the prefs for simplicity
- extract($prefs);
-
- // Are we backing up a complete database or individual tables?
- if (count($tables) == 0)
- {
- $tables = $this->list_tables();
- }
-
- // Start buffering the output
- ob_start();
+ extract($params);
// Build the output
- foreach ($tables as $table)
+ $output = '';
+ foreach ((array)$tables as $table)
{
// Is the table in the "ignore" list?
- if (in_array($table, $ignore))
+ if (in_array($table, (array)$ignore, TRUE))
{
continue;
}
@@ -190,11 +134,11 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Write out the table schema
- echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
+ $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
if ($add_drop == TRUE)
{
- echo 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
+ $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
}
$i = 0;
@@ -203,7 +147,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
{
if ($i++ % 2)
{
- echo $val.';'.$newline.$newline;
+ $output .= $val.';'.$newline.$newline;
}
}
@@ -270,27 +214,16 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
$val_str = preg_replace( "/, $/" , "" , $val_str);
-
- if ($action == 'echo')
- {
- $val_str = htmlspecialchars($val_str);
- }
-
+
// Build the INSERT string
- echo 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
+ $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
}
-
-
- $buffer = ob_get_contents();
- @ob_end_clean();
-
- echo $buffer;
-
+ $output .= $newline.$newline;
}
-
+ return $output;
}
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index b158cfefe..a2c380355 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -284,7 +284,35 @@ class CI_DB_mysqli_driver extends CI_DB {
$row = $query->row();
return $row->numrows;
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ return "SHOW DATABASES";
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SHOW TABLES FROM `".$this->database."`";
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 754ffbda2..f5b98b11f 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -53,34 +53,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- return "SHOW DATABASES";
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SHOW TABLES FROM `".$this->db->database."`";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* @access private
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index bc0a100c2..b43b4c41f 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -399,6 +399,34 @@ class CI_DB_oci8_driver extends CI_DB {
return $row->NUMROWS;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SELECT TABLE_NAME FROM ALL_TABLES";
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 4d267dc6a..b6503de63 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -54,34 +54,6 @@ class CI_DB_oci8_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- return FALSE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SELECT TABLE_NAME FROM ALL_TABLES";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* @access private
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index cdde2e2ea..0f002cc1b 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -259,6 +259,39 @@ class CI_DB_odbc_driver extends CI_DB {
$row = $query->row();
return $row->numrows;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ // Not sure if ODBC lets you list all databases...
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SHOW TABLES FROM `".$this->database."`";
+ }
// --------------------------------------------------------------------
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 3d420f69d..6d0fb79f1 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -36,9 +36,9 @@ class CI_DB_odbc_utility extends CI_DB_utility {
{
// ODBC has no "create database" command since it's
// designed to connect to an existing database
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
@@ -56,9 +56,9 @@ class CI_DB_odbc_utility extends CI_DB_utility {
{
// ODBC has no "drop database" command since it's
// designed to connect to an existing database
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
@@ -66,39 +66,6 @@ class CI_DB_odbc_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- // Not sure if ODBC lets you list all databases...
- if ($this->db_debug)
- {
- return $this->display_error('db_unsuported_feature');
- }
- return FALSE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SHOW TABLES FROM `".$this->db->database."`";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* @access private
@@ -107,9 +74,9 @@ class CI_DB_odbc_utility extends CI_DB_utility {
function _drop_table($table)
{
// Not a supported ODBC feature
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
@@ -128,9 +95,9 @@ class CI_DB_odbc_utility extends CI_DB_utility {
function _optimize_table($table)
{
// Not a supported ODBC feature
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
@@ -149,9 +116,9 @@ class CI_DB_odbc_utility extends CI_DB_utility {
function _repair_table($table)
{
// Not a supported ODBC feature
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 026284118..f14395638 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -286,6 +286,34 @@ class CI_DB_postgre_driver extends CI_DB {
$row = $query->row();
return $row->numrows;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ return "SELECT datname FROM pg_database";
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
+ }
// --------------------------------------------------------------------
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index 7b51c3fe7..46c98cc7d 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -54,34 +54,6 @@ class CI_DB_postgre_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- return "SELECT datname FROM pg_database";
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* @access private
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 45dd7a892..f57c4b8c8 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -278,7 +278,44 @@ class CI_DB_sqlite_driver extends CI_DB {
$row = $query->row();
return $row->numrows;
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * I don't believe you can do a database listing with SQLite
+ * since each database is its own file. I suppose we could
+ * try reading a directory looking for SQLite files, but
+ * that doesn't seem like a terribly good idea
+ *
+ * @access private
+ * @return bool
+ */
+ function _list_databases()
+ {
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_unsuported_feature');
+ }
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List table query
+ *
+ * Generates a platform-specific query string so that the table names can be fetched
+ *
+ * @access private
+ * @return string
+ */
+ function _list_tables()
+ {
+ return "SELECT name from sqlite_master WHERE type='table'";
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index ae241db87..801660d94 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -52,9 +52,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
{
if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database))
{
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unable_to_drop');
+ return $this->db->display_error('db_unable_to_drop');
}
return FALSE;
}
@@ -64,44 +64,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * I don't believe you can do a database listing with SQLite
- * since each database is its own file. I suppose we could
- * try reading a directory looking for SQLite files, but
- * that doesn't seem like a terribly good idea
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
-
- if ($this->db_debug)
- {
- return $this->display_error('db_unsuported_feature');
- }
- return array();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @access private
- * @return string
- */
- function _list_tables()
- {
- return "SELECT name from sqlite_master WHERE type='table'";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Drop Table
*
* Unsupported feature in SQLite
@@ -111,9 +73,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
*/
function _drop_table($table)
{
- if ($this->db_debug)
+ if ($this->db->db_debug)
{
- return $this->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsuported_feature');
}
return array();
}
diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php
index 5be7d6efb..392990120 100644
--- a/system/language/english/db_lang.php
+++ b/system/language/english/db_lang.php
@@ -14,6 +14,9 @@ $lang['db_unsupported_function'] = 'This feature is not available for the databa
$lang['db_transaction_failure'] = 'Transaction failure: Rollback performed';
$lang['db_unable_to_drop'] = 'Unable to drop the specified database.';
$lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.';
+$lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.';
+$lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.';
+
?> \ No newline at end of file
diff --git a/user_guide/database/fields.html b/user_guide/database/fields.html
index 5c872eca9..260cd222f 100644
--- a/user_guide/database/fields.html
+++ b/user_guide/database/fields.html
@@ -65,17 +65,14 @@ Field Names
<h1>Field Data</h1>
-<h2>Retrieving Field Names</h2>
-<p>Sometimes it's helpful to gather the field names for a particular table or with a paritcular query result.</p>
-
-<h2>$this->db->field_names();</h2>
+<h2>$this->db->list_fields();</h2>
<p>Returns an array containing the field names. This query can be called two ways:</p>
<p>1. You can supply the table name and call it from the <dfn>$this->db-></dfn> object:</p>
<code>
-$fields = $this->db->field_names('table_name');<br /><br />
+$fields = $this->db->list_fields('table_name');<br /><br />
foreach ($fields as $field)<br />
{<br />
@@ -90,7 +87,7 @@ from your query result object:</p>
$query = $this->db->query('SELECT * FROM some_table');
<br /><br />
-foreach ($query->field_names() as $field)<br />
+foreach ($query->list_fields() as $field)<br />
{<br />
&nbsp;&nbsp;&nbsp;echo $field;<br />
}
@@ -98,13 +95,10 @@ foreach ($query->field_names() as $field)<br />
-
-
-<h2>Retrieving Field MetaData</h2>
-<p>Sometimes it's helpful to gather the field names or other metadata, like the column type, max length, etc.</p>
-
<h2>$this->db->field_data();</h2>
<p>Returns an array of objects containing field information.</p>
+<p>Sometimes it's helpful to gather the field names or other metadata, like the column type, max length, etc.</p>
+
<p class="important">Note: Not all databases provide meta-data.</p>
diff --git a/user_guide/database/index.html b/user_guide/database/index.html
index 78f90478f..3af6edee8 100644
--- a/user_guide/database/index.html
+++ b/user_guide/database/index.html
@@ -76,6 +76,7 @@ structures and Active Record patterns. The database functions offer clear, simpl
<li><a href="helpers.html">Query Helper Functions</a></li>
<li><a href="active_record.html">Active Record Class</a></li>
<li><a href="transactions.html">Transactions</a></li>
+ <li><a href="table_data.html">Table MetaData</a></li>
<li><a href="fields.html">Field MetaData</a></li>
<li><a href="call_function.html">Custom Function Calls</a></li>
<li><a href="utilities.html">Database Utilities Class</a></li>
diff --git a/user_guide/database/table_data.html b/user_guide/database/table_data.html
index f3df176ed..299e6dc3e 100644
--- a/user_guide/database/table_data.html
+++ b/user_guide/database/table_data.html
@@ -62,15 +62,17 @@ Table Data
<!-- START CONTENT -->
<div id="content">
+
+
<h1>Table Data</h1>
<p>These functions let you fetch table information.</p>
-<h2>$this->db->tables();</h2>
+<h2>$this->db->list_tables();</h2>
<p>Returns an array containing the names of all the tables in the database you are currently connected to. Example:</p>
-<code>$tables = $this->db->tables()<br />
+<code>$tables = $this->db->list_tables()<br />
<br />
foreach ($tables as $table)<br />
{<br />
diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html
index b064c7983..2cc3f5219 100644
--- a/user_guide/database/utilities.html
+++ b/user_guide/database/utilities.html
@@ -119,34 +119,6 @@ foreach($dbs as $db)<br />
-<h2>$this->dbutil->list_tables();</h2>
-
-<p>Returns an array containing the names of all the tables in the database you are currently connected to. Example:</p>
-
-<code>$tables = $this->dbutil->list_tables()<br />
-<br />
-foreach ($tables as $table)<br />
-{<br />
-&nbsp;&nbsp;&nbsp; echo $table;<br />
-}
-</code>
-
-
-<h2>$this->dbutil->table_exists();</h2>
-
-<p>Sometimes it's helpful to know whether a particular table exists before running an operation on it.
-Returns a boolean TRUE/FALSE. Usage example:</p>
-
-<code>
-if ($this->dbutil->table_exists('table_name'))<br />
-{<br />
-&nbsp;&nbsp;&nbsp; // some code...<br />
-}
-</code>
-
-<p>Note: Replace <em>table_name</em> with the name of the table you are looking for.</p>
-
-
<h2>$this->dbutil->optimize_table('table_name');</h2>
<p>Permits you to optimize a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:</p>
@@ -245,6 +217,10 @@ echo $this->dbutil->cvs_from_result($query, $config);
If you need to write the file use the <a href="../helpers/file_helper.html">File Helper</a>.</p>
+<h2>$this->dbutil->export()</h2>
+
+<p>Permits you to export your database or any desired tables. Export data can be downloaded to your desktop, archived to your
+server, or simply displayed. Archived files can be compressed.