diff options
author | Timothy Warren <tim@timshomepage.net> | 2011-09-23 16:28:13 +0200 |
---|---|---|
committer | Timothy Warren <tim@timshomepage.net> | 2011-09-23 16:28:13 +0200 |
commit | 4d292bdb56ba6afc26878d9bcd82892f48d9f1a4 (patch) | |
tree | a894323d2e896adcb7d25d7d1edb806295147384 /user_guide/database | |
parent | 5fc36d8c9dc0bd5d41ed7dea36f999c6e07e1615 (diff) | |
parent | d26133be24eef68b1bead61e7e808f4424a71a0a (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Diffstat (limited to 'user_guide/database')
-rw-r--r-- | user_guide/database/active_record.html | 37 | ||||
-rw-r--r-- | user_guide/database/forge.html | 4 |
2 files changed, 40 insertions, 1 deletions
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html index 10259a4af..70aecbdb5 100644 --- a/user_guide/database/active_record.html +++ b/user_guide/database/active_record.html @@ -543,7 +543,7 @@ $data = array(<br /> )<br /> );<br /> <br /> -$this->db->update_batch('mytable', $data); +$this->db->insert_batch('mytable', $data); <br /><br /> // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')</code> @@ -666,6 +666,41 @@ You can optionally pass this information directly into the update function as a <p>You may also use the <dfn>$this->db->set()</dfn> function described above when performing updates.</p> +<h2>$this->db->update_batch();</h2> +<p>Generates an update string based on the data you supply, and runs the query. You can either pass an +<strong>array</strong> or an <strong>object</strong> to the function. Here is an example using an array:</p> + +<code> +$data = array(<br/> + array(<br /> + 'title' => 'My title' ,<br /> + 'name' => 'My Name 2' ,<br /> + 'date' => 'My date 2'<br /> + ),<br /> + array(<br /> + 'title' => 'Another title' ,<br /> + 'name' => 'Another Name 2' ,<br /> + 'date' => 'Another date 2'<br /> + )<br/> +);<br /> +<br /> +$this->db->update_batch('mytable', $data, 'title'); +<br /><br /> +// Produces: <br /> +// UPDATE `mytable` SET `name` = CASE<br /> +// WHEN `title` = 'My title' THEN 'My Name 2'<br /> +// WHEN `title` = 'Another title' THEN 'Another Name 2'<br /> +// ELSE `name` END,<br /> +// `date` = CASE <br /> +// WHEN `title` = 'My title' THEN 'My date 2'<br /> +// WHEN `title` = 'Another title' THEN 'Another date 2'<br /> +// ELSE `date` END<br /> +// WHERE `title` IN ('My title','Another title')</code> + +<p>The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.</p> + +<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p> + <a name="delete"> </a> <h1>Deleting Data</h1> diff --git a/user_guide/database/forge.html b/user_guide/database/forge.html index 6b8709892..528d1a24c 100644 --- a/user_guide/database/forge.html +++ b/user_guide/database/forge.html @@ -201,6 +201,10 @@ already be running, since the forge class relies on it.</p> $this->dbforge->add_column('table_name', $fields);<br /> <br /> // gives ALTER TABLE table_name ADD preferences TEXT</code></p> +<p>An optional third parameter can be used to specify which existing column to add the new column after.</p> +<p><code> +$this->dbforge->add_column('table_name', $fields, 'after_field'); +</code></p> <h2>$this->dbforge->drop_column()</h2> <p>Used to remove a column from a table. </p> <p><code>$this->dbforge->drop_column('table_name', 'column_to_drop');</code></p> |