From 32cb0e53301575b57c14760ea01649719a435c5e Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 20:36:59 +0000 Subject: --- user_guide/database/utilities.html | 102 ++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 12 deletions(-) (limited to 'user_guide') diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html index 2cc3f5219..5e59358c5 100644 --- a/user_guide/database/utilities.html +++ b/user_guide/database/utilities.html @@ -66,12 +66,28 @@ Database Utilities Class

The Database Utilities Class contains functions that help you manage your database.

+

Table of Contents

+ + + + + +

Initializing the Utilities Class

+

Important:  This class must be initialized independently since it is a separate class from the main Database class. More info below...

- -

Initializing the Utilities Class

-

To initialize this class please use the following code:

$this->load->dbutil() @@ -84,6 +100,7 @@ More info below...

+

$this->dbutil->create_database('db_name')

Permits you to create a database using the name specified in the first parameter. Returns TRUE/FALSE based on success or failure:

@@ -94,6 +111,8 @@ More info below...

} + +

$this->dbutil->drop_database('table_name')

Permits you to drop a database using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:

@@ -104,8 +123,8 @@ More info below...

} +

$this->dbutil->list_databases()

-

Returns an array of database names:

@@ -118,7 +137,7 @@ foreach($dbs as $db)
} - +

$this->dbutil->optimize_table('table_name');

Permits you to optimize a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:

@@ -133,6 +152,7 @@ if ($this->dbutil->optimize_table('table_name'))

Note: Not all database platforms support table optimization.

+

$this->dbutil->repair_table('table_name');

Permits you to repair a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:

@@ -147,13 +167,13 @@ if ($this->dbutil->optimize_table('table_name'))

Note: Not all database platforms support table repairs.

- +

$this->dbutil->optimize_database();

Permits you to optimize the database your DB class is currently connected to. Returns an array containing the returned status messages or FALSE on failure.

-$result = $this->dbutil->optimize_databas();
+$result = $this->dbutil->optimize_databass();

if ($result !== FALSE)
{
@@ -164,7 +184,7 @@ if ($result !== FALSE)

Note: Not all database platforms support table optimization.

- +

$this->dbutil->cvs_from_result($db_result)

Permits you to generate a CVS file from a query result. The first parameter of the function must contain the result object from your query. @@ -192,7 +212,7 @@ echo $this->dbutil->cvs_from_result($query, $delimiter, $newline); If you need to write the file use the File Helper.

- +

$this->dbutil->xml_from_result($db_result)

Permits you to generate an XML file from a query result. The first parameter expects a query result object, the second @@ -217,12 +237,70 @@ echo $this->dbutil->cvs_from_result($query, $config); If you need to write the file use the File Helper.

-

$this->dbutil->export()

+ +

$this->dbutil->backup()

-

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. +

Permits you to backup your full database or individual tables. The backup data can be compressed in either Zip or Gzip format, +and it can be downloaded to your desktop, archived to your +server, returned as a string, or simply displayed. Example:

+$this->dbutil->backup();

+// When no parameters are passed the full database is backed up and downloaded to your desktop as a Gzip file. +
+ +

Setting Backup Preferences

+ +

Preferences are set by submitting an array of values to the first parameter of the backup function. Example:

+ +$prefs = array(
+                'tables'      => array('table1', 'table2'),  // Array of tables to backup.
+                'ignore'      => array(),             // List of tables to omit from the backup
+                'format'      => 'txt',               // gzip, zip, txt
+                'action'      => 'archive',           // download, archive, echo, return
+                'filename'    => 'sql_archive',       // File name - no file extension!
+                'filepath'    => '/path/to/folder/',  // Path needed only when archiving to your server
+                'add_drop'    => TRUE,                // Whether to add DROP TABLE statements to backup file
+                'add_insert'  => TRUE,                // Whether to add INSERT data to backup file
+                'newline'     => "\n"                 // Newline character used in backup file
+              );
+
+$this->dbutil->backup($prefs); +
+ +

Description of Backup Preferences

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
tablesempty arrayNoneAn array of tables you would liked backed up. If left blank all tables will be exported.
ignoreempty arrayNoneAn array of tables you would liked the backup routine to ignore.
formatgzipgzip, zip, txtThe file format of the export file.
actiondownloaddownload, archive, echo, returnWhat action you would like applied to the data. "download" sends it to your desktop, "archive" writes the file to your server, "return" returns the backup as a string, and "echo" simply echos it out for viewing.
filenamethe current date/timeNoneThe name of the export file. DO NOT include the file extension.
filepathempty stringNoneThe path to the directory where you would like the archived file written to. Used ONLY when the "archive" action is set.
add_dropTRUETRUE/FALSEWhether to include DROP TABLE statements in your SQL export file.
add_insert/strong>TRUETRUE/FALSEWhether to include INSERT statements in your SQL export file.
newline/strong>"\n""\n", "\r", "\r\n"Type of newline to use in your SQL export file.
+

VERY IMPORTANT: If you are using the download action to send the file to your desktop, +DO NOT display any data in the controller in which you are triggering the backup. Since Code Igniter buffers all output, any data +sent to the browser will be included in your export file. This issue ONLY applies to downloads. If you are using any other action +you can display data in your controller.

-- cgit v1.2.3-24-g4f1b