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(-) (limited to 'user_guide/database') 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 From 19277f05c20a3de4beaebcac722659a0ed30a374 Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Thu, 22 Sep 2011 11:17:58 -0700 Subject: Documented third $after_field parameter of dbforge->add_column() --- user_guide/database/forge.html | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'user_guide/database') 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.

$this->dbforge->add_column('table_name', $fields);

// gives ALTER TABLE table_name ADD preferences TEXT

+

An optional third parameter can be used to specify which existing column to add the new column after.

+

+$this->dbforge->add_column('table_name', $fields, 'after_field'); +

$this->dbforge->drop_column()

Used to remove a column from a table.

$this->dbforge->drop_column('table_name', 'column_to_drop');

-- cgit v1.2.3-24-g4f1b