From 3b60ae4ea69a5cfda4561dafd502f8dcc742222e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 23:26:03 +0000 Subject: --- user_guide/database/utilities.html | 199 +++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 user_guide/database/utilities.html (limited to 'user_guide/database') diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html new file mode 100644 index 000000000..70d6664d9 --- /dev/null +++ b/user_guide/database/utilities.html @@ -0,0 +1,199 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.1

+
+ + + + + + + + + +
+ + + +
+ + + +
+ +

Database Utilities Class

+ +

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

+ +

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() + +

You can also autoload this class from within your config/autoload.php file by specifying dbutil in the $autoload['libraries'] array.

+ +

Once initialized you will access the functions using the $this->dbutil object:

+ +$this->dbutil->some_function() + + + +

$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:

+ +if ($this->dbutil->create_database('my_db'))
+{
+    echo 'Database created!';
+}
+ + +

$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:

+ +if ($this->dbutil->drop_database('my_db'))
+{
+    echo 'Database deleted!';
+}
+ + +

$this->dbutil->list_databases()

+ +

Returns an array of database names:

+ + + +$dbs = $this->dbutil->list_databases();
+
+foreach($dbs as $db)
+{
+    echo $db;
+}
+ + + +

$this->dbutil->list_tables();

+ +

Returns an array containing the names of all the tables in the database you are currently connected to. Example:

+ +$tables = $this->dbutil->list_tables()
+
+foreach ($tables as $table)
+{
+    echo $table;
+} +
+ + +

$this->dbutil->table_exists();

+ +

Sometimes it's helpful to know whether a particular table exists before running an operation on it. +Returns a boolean TRUE/FALSE. Usage example:

+ + +if ($this->dbutil->table_exists('table_name'))
+{
+    // some code...
+} +
+ +

Note: Replace table_name with the name of the table you are looking for.

+ + +

$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:

+ + +if ($this->dbutil->optimize_table('table_name'))
+{
+    echo 'Success!'
+} +
+ +

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:

+ + +if ($this->dbutil->optimize_table('table_name'))
+{
+    echo 'Success!'
+} +
+ +

Note: Not all database platforms support table repairs.

+ + + + + + + +
+ + + + + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b