summaryrefslogtreecommitdiffstats
path: root/user_guide/database
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-09-18 01:11:37 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-09-18 01:11:37 +0200
commit4ff4896dbc6bd24efc3d005df90bdb3667255f09 (patch)
treee6f15498a08899af890d620d3b5dd45b6017b70f /user_guide/database
parent0ea96950241ddea55318091b3dc91914fa582987 (diff)
parent45697901e4a44ecf1411a21a6014c8ff16e20c91 (diff)
Merge pull request #448 from saintnicster/patch-1
Fix INSERT_BATCH documentation, add UPDATE_BATCH documenation
Diffstat (limited to 'user_guide/database')
-rw-r--r--user_guide/database/active_record.html37
1 files changed, 36 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 />
&nbsp;&nbsp;&nbsp;)<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/>
+&nbsp;&nbsp;&nbsp;array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'My Name 2' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'My date 2'<br />
+&nbsp;&nbsp;&nbsp;),<br />
+&nbsp;&nbsp;&nbsp;array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'Another title' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'Another Name 2' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'Another date 2'<br />
+&nbsp;&nbsp;&nbsp;)<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">&nbsp;</a>
<h1>Deleting Data</h1>