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. |
| 100 | |
| 101 | :: |
| 102 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 103 | $fields = array( |
| 104 | 'blog_id' => array( |
| 105 | 'type' => 'INT', |
| 106 | 'constraint' => 5, |
| 107 | 'unsigned' => TRUE, |
| 108 | 'auto_increment' => TRUE |
| 109 | ), |
| 110 | 'blog_title' => array( |
| 111 | 'type' => 'VARCHAR', |
| 112 | 'constraint' => '100', |
| 113 | ), |
| 114 | 'blog_author' => array( |
| 115 | 'type' =>'VARCHAR', |
| 116 | 'constraint' => '100', |
| 117 | 'default' => 'King of Town', |
| 118 | ), |
| 119 | 'blog_description' => array( |
| 120 | 'type' => 'TEXT', |
| 121 | 'null' => TRUE, |
| 122 | ), |
| 123 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 124 | |
| 125 | |
| 126 | After the fields have been defined, they can be added using |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 127 | ``$this->dbforge->add_field($fields);`` followed by a call to the |
| 128 | ``create_table()`` method. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 129 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 130 | **$this->dbforge->add_field()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 131 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 132 | The add fields method will accept the above array. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 133 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 134 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 135 | Passing strings as fields |
| 136 | ------------------------- |
| 137 | |
| 138 | If you know exactly how you want a field to be created, you can pass the |
| 139 | string into the field definitions with add_field() |
| 140 | |
| 141 | :: |
| 142 | |
| 143 | $this->dbforge->add_field("label varchar(100) NOT NULL DEFAULT 'default label'"); |
| 144 | |
| 145 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 146 | .. note:: Multiple calls to add_field() are cumulative. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 147 | |
| 148 | Creating an id field |
| 149 | -------------------- |
| 150 | |
| 151 | There is a special exception for creating id fields. A field with type |
| 152 | id will automatically be assinged as an INT(9) auto_incrementing |
| 153 | Primary Key. |
| 154 | |
| 155 | :: |
| 156 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 157 | $this->dbforge->add_field('id'); |
| 158 | // gives id INT(9) NOT NULL AUTO_INCREMENT |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 159 | |
| 160 | |
| 161 | Adding Keys |
| 162 | =========== |
| 163 | |
| 164 | Generally speaking, you'll want your table to have Keys. This is |
| 165 | accomplished with $this->dbforge->add_key('field'). An optional second |
| 166 | parameter set to TRUE will make it a primary key. Note that add_key() |
| 167 | must be followed by a call to create_table(). |
| 168 | |
| 169 | Multiple column non-primary keys must be sent as an array. Sample output |
| 170 | below is for MySQL. |
| 171 | |
| 172 | :: |
| 173 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 174 | $this->dbforge->add_key('blog_id', TRUE); |
| 175 | // gives PRIMARY KEY `blog_id` (`blog_id`) |
| 176 | |
| 177 | $this->dbforge->add_key('blog_id', TRUE); |
| 178 | $this->dbforge->add_key('site_id', TRUE); |
| 179 | // gives PRIMARY KEY `blog_id_site_id` (`blog_id`, `site_id`) |
| 180 | |
| 181 | $this->dbforge->add_key('blog_name'); |
| 182 | // gives KEY `blog_name` (`blog_name`) |
| 183 | |
| 184 | $this->dbforge->add_key(array('blog_name', 'blog_label')); |
| 185 | // gives KEY `blog_name_blog_label` (`blog_name`, `blog_label`) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 186 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 187 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 188 | Creating a table |
| 189 | ================ |
| 190 | |
| 191 | After fields and keys have been declared, you can create a new table |
| 192 | with |
| 193 | |
| 194 | :: |
| 195 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 196 | $this->dbforge->create_table('table_name'); |
| 197 | // gives CREATE TABLE table_name |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 198 | |
| 199 | |
| 200 | An optional second parameter set to TRUE adds an "IF NOT EXISTS" clause |
| 201 | into the definition |
| 202 | |
| 203 | :: |
| 204 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 205 | $this->dbforge->create_table('table_name', TRUE); |
| 206 | // gives CREATE TABLE IF NOT EXISTS table_name |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 207 | |
Andrey Andreev | 27f798b | 2014-01-20 18:19:13 +0200 | [diff] [blame] | 208 | You could also pass optional table attributes, such as MySQL's ``ENGINE``:: |
| 209 | |
| 210 | $attributes = array('ENGINE' => 'InnoDB'); |
| 211 | $this->dbforge->create_table('table_name', FALSE, $attributes); |
| 212 | // produces: CREATE TABLE `table_name` (...) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci |
| 213 | |
| 214 | .. note:: Unless you specify the ``CHARACTER SET`` and/or ``COLLATE`` attributes, |
| 215 | ``create_table()`` will always add them with your configured *char_set* |
| 216 | and *dbcollat* values, as long as they are not empty (MySQL only). |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 217 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 218 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 219 | Dropping a table |
| 220 | ================ |
| 221 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 222 | Execute a DROP TABLE statement and optionally add an IF EXISTS clause. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 223 | |
| 224 | :: |
| 225 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 226 | // Produces: DROP TABLE table_name |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 227 | $this->dbforge->drop_table('table_name'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 228 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 229 | // Produces: DROP TABLE IF EXISTS table_name |
| 230 | $this->dbforge->drop_table('table_name'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 231 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 232 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 233 | Renaming a table |
| 234 | ================ |
| 235 | |
| 236 | Executes a TABLE rename |
| 237 | |
| 238 | :: |
| 239 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 240 | $this->dbforge->rename_table('old_table_name', 'new_table_name'); |
| 241 | // gives ALTER TABLE old_table_name RENAME TO new_table_name |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 242 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 243 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 244 | **************** |
| 245 | Modifying Tables |
| 246 | **************** |
| 247 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 248 | Adding a Column to a Table |
| 249 | ========================== |
| 250 | |
| 251 | **$this->dbforge->add_column()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 252 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 253 | The ``add_column()`` method is used to modify an existing table. It |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 254 | accepts the same field array as above, and can be used for an unlimited |
| 255 | number of additional fields. |
| 256 | |
| 257 | :: |
| 258 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 259 | $fields = array( |
| 260 | 'preferences' => array('type' => 'TEXT') |
| 261 | ); |
| 262 | $this->dbforge->add_column('table_name', $fields); |
Andrey Andreev | b67277b | 2012-11-12 12:51:14 +0200 | [diff] [blame] | 263 | // Executes: ALTER TABLE table_name ADD preferences TEXT |
| 264 | |
| 265 | If you are using MySQL or CUBIRD, then you can take advantage of their |
| 266 | AFTER and FIRST clauses to position the new column. |
| 267 | |
| 268 | Examples:: |
| 269 | |
| 270 | // Will place the new column after the `another_field` column: |
| 271 | $fields = array( |
| 272 | 'preferences' => array('type' => 'TEXT', 'after' => 'another_field') |
| 273 | ); |
| 274 | |
| 275 | // Will place the new column at the start of the table definition: |
| 276 | $fields = array( |
| 277 | 'preferences' => array('type' => 'TEXT', 'first' => TRUE) |
| 278 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 279 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 280 | |
| 281 | Dropping a Column From a Table |
| 282 | ============================== |
| 283 | |
| 284 | **$this->dbforge->drop_column()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 285 | |
| 286 | Used to remove a column from a table. |
| 287 | |
| 288 | :: |
| 289 | |
| 290 | $this->dbforge->drop_column('table_name', 'column_to_drop'); |
| 291 | |
| 292 | |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 293 | |
| 294 | Modifying a Column in a Table |
| 295 | ============================= |
| 296 | |
| 297 | **$this->dbforge->modify_column()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 298 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 299 | The usage of this method is identical to ``add_column()``, except it |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 300 | alters an existing column rather than adding a new one. In order to |
| 301 | change the name you can add a "name" key into the field defining array. |
| 302 | |
| 303 | :: |
| 304 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 305 | $fields = array( |
| 306 | 'old_name' => array( |
| 307 | 'name' => 'new_name', |
| 308 | 'type' => 'TEXT', |
| 309 | ), |
| 310 | ); |
| 311 | $this->dbforge->modify_column('table_name', $fields); |
James L Parry | 4828f89 | 2014-11-25 12:53:53 -0800 | [diff] [blame] | 312 | // gives ALTER TABLE table_name CHANGE old_name new_name TEXT |
| 313 | |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 314 | |
| 315 | *************** |
| 316 | Class Reference |
| 317 | *************** |
| 318 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 319 | .. class:: CI_DB_forge |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 320 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 321 | .. method:: add_column($table[, $field = array()[, $_after = NULL]]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 322 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 323 | :param string $table: Table name to add the column to |
| 324 | :param array $field: Column definition(s) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 325 | :param string $_after: Column for AFTER clause (deprecated) |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 326 | :returns: TRUE on success, FALSE on failure |
| 327 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 328 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 329 | 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] | 330 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 331 | .. method:: add_field($field) |
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 | :param array $field: Field definition to add |
| 334 | :returns: CI_DB_forge instance (method chaining) |
| 335 | :rtype: CI_DB_forge |
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 | 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] | 338 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 339 | .. method:: add_key($key[, $primary = FALSE]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 340 | |
| 341 | :param array $key: Name of a key field |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 342 | :param bool $primary: Set to TRUE if it should be a primary key or a regular one |
| 343 | :returns: CI_DB_forge instance (method chaining) |
| 344 | :rtype: CI_DB_forge |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 345 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 346 | 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] | 347 | |
| 348 | .. method:: create_database($db_name) |
| 349 | |
| 350 | :param string $db_name: Name of the database to create |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 351 | :returns: TRUE on success, FALSE on failure |
| 352 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 353 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 354 | Creates a new database. Usage: See `Creating and Dropping Databases`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 355 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 356 | .. method:: create_table($table[, $if_not_exists = FALSE[, array $attributes = array()]]) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 357 | |
| 358 | :param string $table: Name of the table to create |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 359 | :param string $if_not_exists: Set to TRUE to add an 'IF NOT EXISTS' clause |
| 360 | :param string $attributes: An associative array of table attributes |
| 361 | :returns: TRUE on success, FALSE on failure |
| 362 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 363 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 364 | Creates a new table. Usage: See `Creating a table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 365 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 366 | .. method:: drop_column($table, $column_name) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 367 | |
| 368 | :param string $table: Table name |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 369 | :param array $column_name: The column name to drop |
| 370 | :returns: TRUE on success, FALSE on failure |
| 371 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 372 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 373 | 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] | 374 | |
| 375 | .. method:: drop_database($db_name) |
| 376 | |
| 377 | :param string $db_name: Name of the database to drop |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 378 | :returns: TRUE on success, FALSE on failure |
| 379 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 380 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 381 | Drops a database. Usage: See `Creating and Dropping Databases`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 382 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 383 | .. method:: drop_table($table_name[, $if_exists = FALSE]) |
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 | :param string $table: Name of the table to drop |
| 386 | :param string $if_exists: Set to TRUE to add an 'IF EXISTS' clause |
| 387 | :returns: TRUE on success, FALSE on failure |
| 388 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 389 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 390 | Drops a table. Usage: See `Dropping a table`_. |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 391 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 392 | .. method:: modify_column($table, $field) |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 393 | |
| 394 | :param string $table: Table name |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 395 | :param array $field: Column definition(s) |
| 396 | :returns: TRUE on success, FALSE on failure |
| 397 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 398 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 399 | 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] | 400 | |
| 401 | .. method:: rename_table($table_name, $new_table_name) |
| 402 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 403 | :param string $table: Current of the table |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 404 | :param string $new_table_name: New name of the table |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 405 | :returns: TRUE on success, FALSE on failure |
| 406 | :rtype: bool |
James L Parry | d96616c | 2014-12-03 01:17:04 -0800 | [diff] [blame] | 407 | |
Andrey Andreev | b906149 | 2014-12-04 16:33:24 +0200 | [diff] [blame] | 408 | Renames a table. Usage: See `Renaming a table`_. |