diff options
author | saintnicster <saintnicster@gmail.com> | 2011-09-14 23:30:21 +0200 |
---|---|---|
committer | Phil Sturgeon <email@philsturgeon.co.uk> | 2011-11-02 10:53:39 +0100 |
commit | 03192a087965e6927a4842e49f5fd825dedd350f (patch) | |
tree | cd77cadec4d2be799488c872bc0d49c7b8fc4b6b | |
parent | 72b5b8a506df81252d71c69336c0de0172f9e616 (diff) |
Copied into GitHub from @kenjis 's bitbucket repo.https://bitbucket.org/kenjis/ci-user-guide/changeset/3d579dd14afe
-rw-r--r-- | user_guide/database/active_record.html | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html index bd3c07d88..17c58c9f1 100644 --- a/user_guide/database/active_record.html +++ b/user_guide/database/active_record.html @@ -546,7 +546,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> @@ -669,6 +669,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> @@ -786,4 +821,4 @@ Next Topic: <a href="transactions.html">Transactions</a> </div> </body> -</html>
\ No newline at end of file +</html> |