summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/database
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/database')
-rw-r--r--user_guide_src/source/database/query_builder.rst32
1 files changed, 21 insertions, 11 deletions
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
index 0a6d98744..737a4230e 100644
--- a/user_guide_src/source/database/query_builder.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -640,18 +640,18 @@ Example::
$sql = $this->db->set($data)->get_compiled_insert('mytable');
echo $sql;
- // Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
+ // Produces string: INSERT INTO mytable (`title`, `name`, `date`) VALUES ('My title', 'My name', 'My date')
The second parameter enables you to set whether or not the query builder query
will be reset (by default it will be--just like $this->db->insert())::
echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE);
- // Produces string: INSERT INTO mytable (title) VALUES ('My Title')
+ // Produces string: INSERT INTO mytable (`title`) VALUES ('My Title')
echo $this->db->set('content', 'My Content')->get_compiled_insert();
- // Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content')
+ // Produces string: INSERT INTO mytable (`title`, `content`) VALUES ('My Title', 'My Content')
The key thing to notice in the above example is that the second query did not
utlize `$this->db->from()` nor did it pass a table name into the first
@@ -730,7 +730,7 @@ or update functions:**
::
$this->db->set('name', $name);
- $this->db->insert('mytable'); // Produces: INSERT INTO mytable (name) VALUES ('{$name}')
+ $this->db->insert('mytable'); // Produces: INSERT INTO mytable (`name`) VALUES ('{$name}')
If you use multiple function called they will be assembled properly
based on whether you are doing an insert or an update::
@@ -740,18 +740,20 @@ based on whether you are doing an insert or an update::
$this->db->set('status', $status);
$this->db->insert('mytable');
-**set()** will also accept an optional third parameter ($escape), that
+**set()** will also accept an optional third parameter (``$escape``), that
will prevent data from being escaped if set to FALSE. To illustrate the
-difference, here is set() used both with and without the escape
+difference, here is ``set()`` used both with and without the escape
parameter.
::
$this->db->set('field', 'field+1', FALSE);
- $this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES (field+1)
- $this->db->set('field', 'field+1');
- $this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES ('field+1')
+ $this->db->where('id', 2);
+ $this->db->update('mytable'); // gives UPDATE mytable SET field = field+1 WHERE id = 2
+ $this->db->set('field', 'field+1');
+ $this->db->where('id', 2);
+ $this->db->update('mytable'); // gives UPDATE `mytable` SET `field` = 'field+1' WHERE `id` = 2
You can also pass an associative array to this function::
@@ -792,7 +794,11 @@ is an example using an array::
$this->db->where('id', $id);
$this->db->update('mytable', $data);
- // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id
+ // Produces:
+ //
+ // UPDATE mytable
+ // SET title = '{$title}', name = '{$name}', date = '{$date}'
+ // WHERE id = $id
Or you can supply an object::
@@ -807,7 +813,11 @@ Or you can supply an object::
$object = new Myclass;
$this->db->where('id', $id);
$this->db->update('mytable', $object);
- // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id
+ // Produces:
+ //
+ // UPDATE `mytable`
+ // SET `title` = '{$title}', `name` = '{$name}', `date` = '{$date}'
+ // WHERE id = `$id`
.. note:: All values are escaped automatically producing safer queries.