diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-11-06 00:11:22 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-11-06 00:11:22 +0100 |
commit | eaa60c71082c1e49f8a48d633347c98b68a387c0 (patch) | |
tree | 41438b0e6fde0dcb3fd2348e5b52dc9c128f88db /user_guide_src/source/database | |
parent | d743cdbe448258cc7f02abf15e8dc797dc6403eb (diff) |
Added possibility to pass custom database objects to DB Forge and DB Utilities
Also, their property is no longer public and the utility class no longer extends CI_DB_forge.
Diffstat (limited to 'user_guide_src/source/database')
-rw-r--r-- | user_guide_src/source/database/forge.rst | 32 | ||||
-rw-r--r-- | user_guide_src/source/database/utilities.rst | 78 |
2 files changed, 65 insertions, 45 deletions
diff --git a/user_guide_src/source/database/forge.rst b/user_guide_src/source/database/forge.rst index 1d6b847b4..de5748b45 100644 --- a/user_guide_src/source/database/forge.rst +++ b/user_guide_src/source/database/forge.rst @@ -2,7 +2,7 @@ Database Forge Class #################### -The Database Forge Class contains functions that help you manage your +The Database Forge Class contains methods that help you manage your database. .. contents:: Table of Contents @@ -18,13 +18,25 @@ Load the Forge Class as follows:: $this->load->dbforge() -Once initialized you will access the functions using the $this->dbforge +You can also pass another database object to the DB Forge loader, in case +the database you want to manage isn't the default one:: + + $this->myforge = $this->load->dbforge($this->other_db, TRUE); + +In the above example, we're passing a custom database object as the first +parameter and then tell it to return the dbforge object, instead of +assigning it directly to ``$this->dbforge``. + +.. note:: Both of the parameters can be used individually, just pass an empty + value as the first one if you wish to skip it. + +Once initialized you will access the methods using the ``$this->dbforge`` object:: - $this->dbforge->some_function() + $this->dbforge->some_method(); $this->dbforge->create_database('db_name') -============================================ +========================================== Permits you to create the database specified in the first parameter. Returns TRUE/FALSE based on success or failure:: @@ -108,13 +120,13 @@ Additionally, the following key/values can be used: After the fields have been defined, they can be added using -$this->dbforge->add_field($fields); followed by a call to the -create_table() function. +``$this->dbforge->add_field($fields);`` followed by a call to the +``create_table()`` method. $this->dbforge->add_field() ----------------------------- +--------------------------- -The add fields function will accept the above array. +The add fields method will accept the above array. Passing strings as fields ------------------------- @@ -221,7 +233,7 @@ Modifying Tables $this->dbforge->add_column() ============================= -The add_column() function is used to modify an existing table. It +The ``add_column()`` method is used to modify an existing table. It accepts the same field array as above, and can be used for an unlimited number of additional fields. @@ -246,7 +258,7 @@ Used to remove a column from a table. $this->dbforge->modify_column() ================================ -The usage of this function is identical to add_column(), except it +The usage of this method is identical to ``add_column()``, except it alters an existing column rather than adding a new one. In order to change the name you can add a "name" key into the field defining array. diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst index 4e83929b2..06ecb2da1 100644 --- a/user_guide_src/source/database/utilities.rst +++ b/user_guide_src/source/database/utilities.rst @@ -2,7 +2,7 @@ Database Utility Class ###################### -The Database Utility Class contains functions that help you manage your +The Database Utility Class contains methods that help you manage your database. .. contents:: Table of Contents @@ -22,12 +22,24 @@ Load the Utility Class as follows:: $this->load->dbutil() -Once initialized you will access the functions using the $this->dbutil +You can also pass another database object to the DB Utility loader, in case +the database you want to manage isn't the default one:: + + $this->myutil = $this->load->dbutil($this->other_db, TRUE); + +In the above example, we're passing a custom database object as the first +parameter and then tell it to return the dbutil object, instead of +assigning it directly to ``$this->dbutil``. + +.. note:: Both of the parameters can be used individually, just pass an empty + value as the first one if you wish to skip it. + +Once initialized you will access the methods using the ``$this->dbutil`` object:: - $this->dbutil->some_function() + $this->dbutil->some_method() -$this->dbutil->list_databases() +$this->dbutil->list_databases(); ================================ Returns an array of database names:: @@ -40,7 +52,7 @@ Returns an array of database names:: } $this->dbutil->database_exists(); -================================== +================================= Sometimes it's helpful to know whether a particular database exists. Returns a boolean TRUE/FALSE. Usage example:: @@ -50,13 +62,11 @@ Returns a boolean TRUE/FALSE. Usage example:: // some code... } -Note: Replace *database_name* with the name of the table you are -looking for. This function is case sensitive. +.. note:: Replace *database_name* with the name of the table you are + looking for. This method is case sensitive. $this->dbutil->optimize_table('table_name'); -============================================== - -.. note:: This features is only available for MySQL/MySQLi databases. +============================================ Permits you to optimize a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:: @@ -66,12 +76,11 @@ first parameter. Returns TRUE/FALSE based on success or failure:: echo 'Success!'; } -.. note:: Not all database platforms support table optimization. +.. note:: Not all database platforms support table optimization. It is + mostly for use with MySQL. $this->dbutil->repair_table('table_name'); -============================================ - -.. note:: This features is only available for MySQL/MySQLi databases. +========================================== Permits you to repair a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:: @@ -86,8 +95,6 @@ first parameter. Returns TRUE/FALSE based on success or failure:: $this->dbutil->optimize_database(); ==================================== -.. note:: This features is only available for MySQL/MySQLi databases. - Permits you to optimize the database your DB class is currently connected to. Returns an array containing the DB status messages or FALSE on failure. @@ -101,13 +108,14 @@ FALSE on failure. print_r($result); } -.. note:: Not all database platforms support table optimization. +.. note:: Not all database platforms support table optimization. It + it is mostly for use with MySQL. -$this->dbutil->csv_from_result($db_result) -============================================= +$this->dbutil->csv_from_result($db_result); +=========================================== Permits you to generate a CSV file from a query result. The first -parameter of the function must contain the result object from your +parameter of the method must contain the result object from your query. Example:: $this->load->dbutil(); @@ -127,12 +135,12 @@ is used as the enclosure. Example:: echo $this->dbutil->csv_from_result($query, $delimiter, $newline, $enclosure); -.. important:: This function will NOT write the CSV file for you. It +.. important:: This method will NOT write the CSV file for you. It simply creates the CSV layout. If you need to write the file use the :doc:`File Helper <../helpers/file_helper>`. -$this->dbutil->xml_from_result($db_result) -============================================= +$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 may contain an @@ -151,17 +159,17 @@ optional array of config parameters. Example:: echo $this->dbutil->xml_from_result($query, $config); -.. important:: This function will NOT write the XML file for you. It +.. important:: This method will NOT write the XML file for you. It simply creates the XML layout. If you need to write the file use the :doc:`File Helper <../helpers/file_helper>`. -$this->dbutil->backup() -======================= +$this->dbutil->backup(); +======================== Permits you to backup your full database or individual tables. The backup data can be compressed in either Zip or Gzip format. -.. note:: This features is only available for MySQL and Interbase/Firebird databases. +.. note:: This feature is only available for MySQL and Interbase/Firebird databases. .. note:: For Interbase/Firebird databases, the backup file name is the only parameter. @@ -196,16 +204,16 @@ Setting Backup Preferences -------------------------- Backup preferences are set by submitting an array of values to the first -parameter of the backup function. Example:: +parameter of the ``backup()`` method. 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 - 'filename' => 'mybackup.sql', // File name - NEEDED ONLY WITH ZIP FILES - '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 + 'tables' => array('table1', 'table2'), // Array of tables to backup. + 'ignore' => array(), // List of tables to omit from the backup + 'format' => 'txt', // gzip, zip, txt + 'filename' => 'mybackup.sql', // File name - NEEDED ONLY WITH ZIP FILES + '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); |