summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/database/forge.rst
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/database/forge.rst')
-rw-r--r--user_guide_src/source/database/forge.rst136
1 files changed, 123 insertions, 13 deletions
diff --git a/user_guide_src/source/database/forge.rst b/user_guide_src/source/database/forge.rst
index 48642ad7e..59a6591b7 100644
--- a/user_guide_src/source/database/forge.rst
+++ b/user_guide_src/source/database/forge.rst
@@ -6,6 +6,7 @@ The Database Forge Class contains methods that help you manage your
database.
.. contents:: Table of Contents
+ :depth: 3
****************************
Initializing the Forge Class
@@ -35,8 +36,11 @@ object::
$this->dbforge->some_method();
-$this->dbforge->create_database('db_name')
-==========================================
+*******************************
+Creating and Dropping Databases
+*******************************
+
+**$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::
@@ -46,8 +50,7 @@ Returns TRUE/FALSE based on success or failure::
echo 'Database created!';
}
-$this->dbforge->drop_database('db_name')
-==========================================
+**$this->dbforge->drop_database('db_name')**
Permits you to drop the database specified in the first parameter.
Returns TRUE/FALSE based on success or failure::
@@ -57,6 +60,7 @@ Returns TRUE/FALSE based on success or failure::
echo 'Database deleted!';
}
+
****************************
Creating and Dropping Tables
****************************
@@ -123,11 +127,11 @@ After the fields have been defined, they can be added using
``$this->dbforge->add_field($fields);`` followed by a call to the
``create_table()`` method.
-$this->dbforge->add_field()
----------------------------
+**$this->dbforge->add_field()**
The add fields method will accept the above array.
+
Passing strings as fields
-------------------------
@@ -211,6 +215,7 @@ You could also pass optional table attributes, such as MySQL's ``ENGINE``::
``create_table()`` will always add them with your configured *char_set*
and *dbcollat* values, as long as they are not empty (MySQL only).
+
Dropping a table
================
@@ -224,6 +229,7 @@ Execute a DROP TABLE statement and optionally add an IF EXISTS clause.
// Produces: DROP TABLE IF EXISTS table_name
$this->dbforge->drop_table('table_name');
+
Renaming a table
================
@@ -239,8 +245,10 @@ Executes a TABLE rename
Modifying Tables
****************
-$this->dbforge->add_column()
-============================
+Adding a Column to a Table
+==========================
+
+**$this->dbforge->add_column()**
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
@@ -269,8 +277,11 @@ Examples::
'preferences' => array('type' => 'TEXT', 'first' => TRUE)
);
-$this->dbforge->drop_column()
-=============================
+
+Dropping a Column From a Table
+==============================
+
+**$this->dbforge->drop_column()**
Used to remove a column from a table.
@@ -279,8 +290,11 @@ Used to remove a column from a table.
$this->dbforge->drop_column('table_name', 'column_to_drop');
-$this->dbforge->modify_column()
-===============================
+
+Modifying a Column in a Table
+=============================
+
+**$this->dbforge->modify_column()**
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
@@ -295,4 +309,100 @@ change the name you can add a "name" key into the field defining array.
),
);
$this->dbforge->modify_column('table_name', $fields);
- // gives ALTER TABLE table_name CHANGE old_name new_name TEXT \ No newline at end of file
+ // gives ALTER TABLE table_name CHANGE old_name new_name TEXT
+
+
+***************
+Class Reference
+***************
+
+.. class:: CI_DB_forge
+
+ .. method:: add_column($table[, $field = array()[, $_after = NULL]])
+
+ :param string $table: Table name to add the column to
+ :param array $field: Column definition(s)
+ :param string $_after: Column for AFTER clause (deprecated)
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Adds a column to a table. Usage: See `Adding a Column to a Table`_.
+
+ .. method:: add_field($field)
+
+ :param array $field: Field definition to add
+ :returns: CI_DB_forge instance (method chaining)
+ :rtype: CI_DB_forge
+
+ Adds a field to the set that will be used to create a table. Usage: See `Adding fields`_.
+
+ .. method:: add_key($key[, $primary = FALSE])
+
+ :param array $key: Name of a key field
+ :param bool $primary: Set to TRUE if it should be a primary key or a regular one
+ :returns: CI_DB_forge instance (method chaining)
+ :rtype: CI_DB_forge
+
+ Adds a key to the set that will be used to create a table. Usage: See `Adding Keys`_.
+
+ .. method:: create_database($db_name)
+
+ :param string $db_name: Name of the database to create
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Creates a new database. Usage: See `Creating and Dropping Databases`_.
+
+ .. method:: create_table($table[, $if_not_exists = FALSE[, array $attributes = array()]])
+
+ :param string $table: Name of the table to create
+ :param string $if_not_exists: Set to TRUE to add an 'IF NOT EXISTS' clause
+ :param string $attributes: An associative array of table attributes
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Creates a new table. Usage: See `Creating a table`_.
+
+ .. method:: drop_column($table, $column_name)
+
+ :param string $table: Table name
+ :param array $column_name: The column name to drop
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Drops a column from a table. Usage: See `Dropping a Column From a Table`_.
+
+ .. method:: drop_database($db_name)
+
+ :param string $db_name: Name of the database to drop
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Drops a database. Usage: See `Creating and Dropping Databases`_.
+
+ .. method:: drop_table($table_name[, $if_exists = FALSE])
+
+ :param string $table: Name of the table to drop
+ :param string $if_exists: Set to TRUE to add an 'IF EXISTS' clause
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Drops a table. Usage: See `Dropping a table`_.
+
+ .. method:: modify_column($table, $field)
+
+ :param string $table: Table name
+ :param array $field: Column definition(s)
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Modifies a table column. Usage: See `Modifying a Column in a Table`_.
+
+ .. method:: rename_table($table_name, $new_table_name)
+
+ :param string $table: Current of the table
+ :param string $new_table_name: New name of the table
+ :returns: TRUE on success, FALSE on failure
+ :rtype: bool
+
+ Renames a table. Usage: See `Renaming a table`_. \ No newline at end of file