Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | #################### |
| 2 | Database Forge Class |
| 3 | #################### |
| 4 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 5 | The Database Forge Class contains methods that help you manage your |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 6 | database. |
| 7 | |
| 8 | .. contents:: Table of Contents |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 9 | :depth: 3 |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 10 | |
| 11 | **************************** |
| 12 | Initializing the Forge Class |
| 13 | **************************** |
| 14 | |
| 15 | .. important:: In order to initialize the Forge class, your database |
| 16 | driver must already be running, since the forge class relies on it. |
| 17 | |
| 18 | Load the Forge Class as follows:: |
| 19 | |
| 20 | $this->load->dbforge() |
| 21 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 22 | You can also pass another database object to the DB Forge loader, in case |
| 23 | the database you want to manage isn't the default one:: |
| 24 | |
| 25 | $this->myforge = $this->load->dbforge($this->other_db, TRUE); |
| 26 | |
| 27 | In the above example, we're passing a custom database object as the first |
| 28 | parameter and then tell it to return the dbforge object, instead of |
| 29 | assigning it directly to ``$this->dbforge``. |
| 30 | |
| 31 | .. note:: Both of the parameters can be used individually, just pass an empty |
| 32 | value as the first one if you wish to skip it. |
| 33 | |
| 34 | Once initialized you will access the methods using the ``$this->dbforge`` |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 35 | object:: |
| 36 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 37 | $this->dbforge->some_method(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 38 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 39 | ******************************* |
| 40 | Creating and Dropping Databases |
| 41 | ******************************* |
| 42 | |
| 43 | **$this->dbforge->create_database('db_name')** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 44 | |
| 45 | Permits you to create the database specified in the first parameter. |
| 46 | Returns TRUE/FALSE based on success or failure:: |
| 47 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 48 | if ($this->dbforge->create_database('my_db')) |
| 49 | { |
| 50 | echo 'Database created!'; |
| 51 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 52 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 53 | **$this->dbforge->drop_database('db_name')** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 54 | |
| 55 | Permits you to drop the database specified in the first parameter. |
| 56 | Returns TRUE/FALSE based on success or failure:: |
| 57 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 58 | if ($this->dbforge->drop_database('my_db')) |
| 59 | { |
| 60 | echo 'Database deleted!'; |
| 61 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 62 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 63 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 64 | **************************** |
| 65 | Creating and Dropping Tables |
| 66 | **************************** |
| 67 | |
| 68 | There are several things you may wish to do when creating tables. Add |
| 69 | fields, add keys to the table, alter columns. CodeIgniter provides a |
| 70 | mechanism for this. |
| 71 | |
| 72 | Adding fields |
| 73 | ============= |
| 74 | |
| 75 | Fields are created via an associative array. Within the array you must |
| 76 | include a 'type' key that relates to the datatype of the field. For |
| 77 | example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR) |
| 78 | also require a 'constraint' key. |
| 79 | |
| 80 | :: |
| 81 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 82 | $fields = array( |
| 83 | 'users' => array( |
| 84 | 'type' => 'VARCHAR', |
| 85 | 'constraint' => '100', |
| 86 | ), |
| 87 | ); |
| 88 | // will translate to "users VARCHAR(100)" when the field is added. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 89 | |
| 90 | |
| 91 | Additionally, the following key/values can be used: |
| 92 | |
| 93 | - unsigned/true : to generate "UNSIGNED" in the field definition. |
| 94 | - default/value : to generate a default value in the field definition. |
| 95 | - null/true : to generate "NULL" in the field definition. Without this, |
| 96 | the field will default to "NOT NULL". |
| 97 | - auto_increment/true : generates an auto_increment flag on the |
| 98 | field. Note that the field type must be a type that supports this, |
| 99 | such as integer. |
Andrey Andreev | e8bcc9e | 2016-02-02 14:01:50 +0200 | [diff] [blame] | 100 | - unique/true : to generate a unique key for the field definition. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 101 | |
| 102 | :: |
| 103 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 104 | $fields = array( |
| 105 | 'blog_id' => array( |
| 106 | 'type' => 'INT', |
| 107 | 'constraint' => 5, |
| 108 | 'unsigned' => TRUE, |
| 109 | 'auto_increment' => TRUE |
| 110 | ), |
| 111 | 'blog_title' => array( |
| 112 | 'type' => 'VARCHAR', |
| 113 | 'constraint' => '100', |
Andrey Andreev | e8bcc9e | 2016-02-02 14:01:50 +0200 | [diff] [blame] | 114 | 'unique' => TRUE, |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 115 | ), |
| 116 | 'blog_author' => array( |
| 117 | 'type' =>'VARCHAR', |
| 118 | 'constraint' => '100', |
| 119 | 'default' => 'King of Town', |
| 120 | ), |
| 121 | 'blog_description' => array( |
| 122 | 'type' => 'TEXT', |
| 123 | 'null' => TRUE, |
| 124 | ), |
| 125 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 126 | |
| 127 | |
| 128 | After the fields have been defined, they can be added using |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 129 | ``$this->dbforge->add_field($fields);`` followed by a call to the |
| 130 | ``create_table()`` method. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 131 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 132 | **$this->dbforge->add_field()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 133 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 134 | The add fields method will accept the above array. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 135 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 136 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 137 | Passing strings as fields |
| 138 | ------------------------- |
| 139 | |
| 140 | If you know exactly how you want a field to be created, you can pass the |
| 141 | string into the field definitions with add_field() |
| 142 | |
| 143 | :: |
| 144 | |
| 145 | $this->dbforge->add_field("label varchar(100) NOT NULL DEFAULT 'default label'"); |
| 146 | |
| 147 | |
Adrian Voicu | ff50c54 | 2015-07-13 11:55:51 +0300 | [diff] [blame] | 148 | .. note:: Passing raw strings as fields cannot be followed by ``add_key()`` calls on those fields. |
Adrian Voicu | 00cdb81 | 2015-07-10 17:04:00 +0300 | [diff] [blame] | 149 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 150 | .. note:: Multiple calls to add_field() are cumulative. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 151 | |
| 152 | Creating an id field |
| 153 | -------------------- |
| 154 | |
| 155 | There is a special exception for creating id fields. A field with type |
gn | b5a4b67 | 2015-06-23 11:41:57 -0500 | [diff] [blame] | 156 | id will automatically be assigned as an INT(9) auto_incrementing |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 157 | Primary Key. |
| 158 | |
| 159 | :: |
| 160 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 161 | $this->dbforge->add_field('id'); |
| 162 | // gives id INT(9) NOT NULL AUTO_INCREMENT |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 163 | |
| 164 | |
| 165 | Adding Keys |
| 166 | =========== |
| 167 | |
| 168 | Generally speaking, you'll want your table to have Keys. This is |
| 169 | accomplished with $this->dbforge->add_key('field'). An optional second |
| 170 | parameter set to TRUE will make it a primary key. Note that add_key() |
| 171 | must be followed by a call to create_table(). |
| 172 | |
| 173 | Multiple column non-primary keys must be sent as an array. Sample output |
| 174 | below is for MySQL. |
| 175 | |
| 176 | :: |
| 177 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 178 | $this->dbforge->add_key('blog_id', TRUE); |
| 179 | // gives PRIMARY KEY `blog_id` (`blog_id`) |
Andrey Andreev | e8bcc9e | 2016-02-02 14:01:50 +0200 | [diff] [blame] | 180 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 181 | $this->dbforge->add_key('blog_id', TRUE); |
| 182 | $this->dbforge->add_key('site_id', TRUE); |
| 183 | // gives PRIMARY KEY `blog_id_site_id` (`blog_id`, `site_id`) |
Andrey Andreev | e8bcc9e | 2016-02-02 14:01:50 +0200 | [diff] [blame] | 184 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 185 | $this->dbforge->add_key('blog_name'); |
| 186 | // gives KEY `blog_name` (`blog_name`) |
Andrey Andreev | e8bcc9e | 2016-02-02 14:01:50 +0200 | [diff] [blame] | 187 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 188 | $this->dbforge->add_key(array('blog_name', 'blog_label')); |
| 189 | // gives KEY `blog_name_blog_label` (`blog_name`, `blog_label`) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 190 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 191 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 192 | Creating a table |
| 193 | ================ |
| 194 | |
| 195 | After fields and keys have been declared, you can create a new table |
| 196 | with |
| 197 | |
| 198 | :: |
| 199 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 200 | $this->dbforge->create_table('table_name'); |
| 201 | // gives CREATE TABLE table_name |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 202 | |
| 203 | |
| 204 | An optional second parameter set to TRUE adds an "IF NOT EXISTS" clause |
| 205 | into the definition |
| 206 | |
| 207 | :: |
| 208 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 209 | $this->dbforge->create_table('table_name', TRUE); |
| 210 | // gives CREATE TABLE IF NOT EXISTS table_name |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 211 | |
Andrey Andreev | 27f798b | 2014-01-20 18:19:13 +0200 | [diff] [blame] | 212 | You could also pass optional table attributes, such as MySQL's ``ENGINE``:: |
| 213 | |
| 214 | $attributes = array('ENGINE' => 'InnoDB'); |
| 215 | $this->dbforge->create_table('table_name', FALSE, $attributes); |
| 216 | // produces: CREATE TABLE `table_name` (...) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci |
| 217 | |
| 218 | .. note:: Unless you specify the ``CHARACTER SET`` and/or ``COLLATE`` attributes, |
| 219 | ``create_table()`` will always add them with your configured *char_set* |
| 220 | and *dbcollat* values, as long as they are not empty (MySQL only). |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 221 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 222 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 223 | Dropping a table |
| 224 | ================ |
| 225 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 226 | Execute a DROP TABLE statement and optionally add an IF EXISTS clause. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 227 | |
| 228 | :: |
| 229 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 230 | // Produces: DROP TABLE table_name |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 231 | $this->dbforge->drop_table('table_name'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 232 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 233 | // Produces: DROP TABLE IF EXISTS table_name |
LouisMilotte | 1db6da3 | 2015-04-04 03:22:12 -0700 | [diff] [blame] | 234 | $this->dbforge->drop_table('table_name',TRUE); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 235 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 236 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 237 | Renaming a table |
| 238 | ================ |
| 239 | |
| 240 | Executes a TABLE rename |
| 241 | |
| 242 | :: |
| 243 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 244 | $this->dbforge->rename_table('old_table_name', 'new_table_name'); |
| 245 | // gives ALTER TABLE old_table_name RENAME TO new_table_name |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 246 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 247 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 248 | **************** |
| 249 | Modifying Tables |
| 250 | **************** |
| 251 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 252 | Adding a Column to a Table |
| 253 | ========================== |
| 254 | |
| 255 | **$this->dbforge->add_column()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 256 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 257 | The ``add_column()`` method is used to modify an existing table. It |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 258 | accepts the same field array as above, and can be used for an unlimited |
| 259 | number of additional fields. |
| 260 | |
| 261 | :: |
| 262 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 263 | $fields = array( |
| 264 | 'preferences' => array('type' => 'TEXT') |
| 265 | ); |
Andrey Andreev | e8bcc9e | 2016-02-02 14:01:50 +0200 | [diff] [blame] | 266 | $this->dbforge->add_column('table_name', $fields); |
Andrey Andreev | b67277b | 2012-11-12 12:51:14 +0200 | [diff] [blame] | 267 | // Executes: ALTER TABLE table_name ADD preferences TEXT |
| 268 | |
| 269 | If you are using MySQL or CUBIRD, then you can take advantage of their |
| 270 | AFTER and FIRST clauses to position the new column. |
| 271 | |
| 272 | Examples:: |
| 273 | |
| 274 | // Will place the new column after the `another_field` column: |
| 275 | $fields = array( |
| 276 | 'preferences' => array('type' => 'TEXT', 'after' => 'another_field') |
| 277 | ); |
| 278 | |
| 279 | // Will place the new column at the start of the table definition: |
| 280 | $fields = array( |
| 281 | 'preferences' => array('type' => 'TEXT', 'first' => TRUE) |
| 282 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 283 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 284 | |
| 285 | Dropping a Column From a Table |
| 286 | ============================== |
| 287 | |
| 288 | **$this->dbforge->drop_column()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 289 | |
| 290 | Used to remove a column from a table. |
| 291 | |
| 292 | :: |
| 293 | |
| 294 | $this->dbforge->drop_column('table_name', 'column_to_drop'); |
| 295 | |
| 296 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 297 | |
| 298 | Modifying a Column in a Table |
| 299 | ============================= |
| 300 | |
| 301 | **$this->dbforge->modify_column()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 302 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 303 | The usage of this method is identical to ``add_column()``, except it |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 304 | alters an existing column rather than adding a new one. In order to |
| 305 | change the name you can add a "name" key into the field defining array. |
| 306 | |
| 307 | :: |
| 308 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 309 | $fields = array( |
| 310 | 'old_name' => array( |
| 311 | 'name' => 'new_name', |
| 312 | 'type' => 'TEXT', |
| 313 | ), |
| 314 | ); |
| 315 | $this->dbforge->modify_column('table_name', $fields); |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 316 | // gives ALTER TABLE table_name CHANGE old_name new_name TEXT |
| 317 | |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 318 | |
| 319 | *************** |
| 320 | Class Reference |
| 321 | *************** |
| 322 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 323 | .. php:class:: CI_DB_forge |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 324 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 325 | .. php:method:: add_column($table[, $field = array()[, $_after = NULL]]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 326 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 327 | :param string $table: Table name to add the column to |
| 328 | :param array $field: Column definition(s) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 329 | :param string $_after: Column for AFTER clause (deprecated) |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 330 | :returns: TRUE on success, FALSE on failure |
| 331 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 332 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 333 | Adds a column to a table. Usage: See `Adding a Column to a Table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 334 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 335 | .. php:method:: add_field($field) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 336 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 337 | :param array $field: Field definition to add |
| 338 | :returns: CI_DB_forge instance (method chaining) |
| 339 | :rtype: CI_DB_forge |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 340 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 341 | Adds a field to the set that will be used to create a table. Usage: See `Adding fields`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 342 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 343 | .. php:method:: add_key($key[, $primary = FALSE]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 344 | |
| 345 | :param array $key: Name of a key field |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 346 | :param bool $primary: Set to TRUE if it should be a primary key or a regular one |
| 347 | :returns: CI_DB_forge instance (method chaining) |
| 348 | :rtype: CI_DB_forge |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 349 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 350 | Adds a key to the set that will be used to create a table. Usage: See `Adding Keys`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 351 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 352 | .. php:method:: create_database($db_name) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 353 | |
| 354 | :param string $db_name: Name of the database to create |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 355 | :returns: TRUE on success, FALSE on failure |
| 356 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 357 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 358 | Creates a new database. Usage: See `Creating and Dropping Databases`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 359 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 360 | .. php:method:: create_table($table[, $if_not_exists = FALSE[, array $attributes = array()]]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 361 | |
| 362 | :param string $table: Name of the table to create |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 363 | :param string $if_not_exists: Set to TRUE to add an 'IF NOT EXISTS' clause |
| 364 | :param string $attributes: An associative array of table attributes |
| 365 | :returns: TRUE on success, FALSE on failure |
| 366 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 367 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 368 | Creates a new table. Usage: See `Creating a table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 369 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 370 | .. php:method:: drop_column($table, $column_name) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 371 | |
| 372 | :param string $table: Table name |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 373 | :param array $column_name: The column name to drop |
| 374 | :returns: TRUE on success, FALSE on failure |
| 375 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 376 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 377 | Drops a column from a table. Usage: See `Dropping a Column From a Table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 378 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 379 | .. php:method:: drop_database($db_name) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 380 | |
| 381 | :param string $db_name: Name of the database to drop |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 382 | :returns: TRUE on success, FALSE on failure |
| 383 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 384 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 385 | Drops a database. Usage: See `Creating and Dropping Databases`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 386 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 387 | .. php:method:: drop_table($table_name[, $if_exists = FALSE]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 388 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 389 | :param string $table: Name of the table to drop |
| 390 | :param string $if_exists: Set to TRUE to add an 'IF EXISTS' clause |
| 391 | :returns: TRUE on success, FALSE on failure |
| 392 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 393 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 394 | Drops a table. Usage: See `Dropping a table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 395 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 396 | .. php:method:: modify_column($table, $field) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 397 | |
| 398 | :param string $table: Table name |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 399 | :param array $field: Column definition(s) |
| 400 | :returns: TRUE on success, FALSE on failure |
| 401 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 402 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 403 | Modifies a table column. Usage: See `Modifying a Column in a Table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 404 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 405 | .. php:method:: rename_table($table_name, $new_table_name) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 406 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 407 | :param string $table: Current of the table |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 408 | :param string $new_table_name: New name of the table |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 409 | :returns: TRUE on success, FALSE on failure |
| 410 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 411 | |
LouisMilotte | 1db6da3 | 2015-04-04 03:22:12 -0700 | [diff] [blame] | 412 | Renames a table. Usage: See `Renaming a table`_. |