From 45697901e4a44ecf1411a21a6014c8ff16e20c91 Mon Sep 17 00:00:00 2001 From: saintnicster Date: Wed, 14 Sep 2011 16:30:21 -0500 Subject: Copied into GitHub from @kenjis 's bitbucket repo.https://bitbucket.org/kenjis/ci-user-guide/changeset/3d579dd14afe --- user_guide/database/active_record.html | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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(
   )
);

-$this->db->update_batch('mytable', $data); +$this->db->insert_batch('mytable', $data);

// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date') @@ -666,6 +666,41 @@ You can optionally pass this information directly into the update function as a

You may also use the $this->db->set() function described above when performing updates.

+

$this->db->update_batch();

+

Generates an update string based on the data you supply, and runs the query. You can either pass an +array or an object to the function. Here is an example using an array:

+ + +$data = array(
+   array(
+      'title' => 'My title' ,
+      'name' => 'My Name 2' ,
+      'date' => 'My date 2'
+   ),
+   array(
+      'title' => 'Another title' ,
+      'name' => 'Another Name 2' ,
+      'date' => 'Another date 2'
+   )
+);
+
+$this->db->update_batch('mytable', $data, 'title'); +

+// Produces:
+// UPDATE `mytable` SET `name` = CASE
+// WHEN `title` = 'My title' THEN 'My Name 2'
+// WHEN `title` = 'Another title' THEN 'Another Name 2'
+// ELSE `name` END,
+// `date` = CASE
+// WHEN `title` = 'My title' THEN 'My date 2'
+// WHEN `title` = 'Another title' THEN 'Another date 2'
+// ELSE `date` END
+// WHERE `title` IN ('My title','Another title')
+ +

The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.

+ +

Note: All values are escaped automatically producing safer queries.

+  

Deleting Data

-- cgit v1.2.3-24-g4f1b