diff options
Diffstat (limited to 'user_guide/database')
-rw-r--r-- | user_guide/database/active_record.html | 43 | ||||
-rw-r--r-- | user_guide/database/connecting.html | 2 | ||||
-rw-r--r-- | user_guide/database/forge.html | 4 | ||||
-rw-r--r-- | user_guide/database/helpers.html | 4 | ||||
-rw-r--r-- | user_guide/database/results.html | 4 | ||||
-rw-r--r-- | user_guide/database/utilities.html | 7 |
6 files changed, 53 insertions, 11 deletions
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html index 0f09e78c3..70aecbdb5 100644 --- a/user_guide/database/active_record.html +++ b/user_guide/database/active_record.html @@ -530,7 +530,7 @@ $this->db->insert('mytable', $object); <strong>array</strong> or an <strong>object</strong> to the function. Here is an example using an array:</p> <code> -$data = array(<br/> +$data = array(<br /> array(<br /> 'title' => 'My title' ,<br /> 'name' => 'My Name' ,<br /> @@ -540,10 +540,10 @@ $data = array(<br/> 'title' => 'Another title' ,<br /> 'name' => 'Another Name' ,<br /> 'date' => 'Another date'<br /> - )<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> @@ -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/> + 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> @@ -783,4 +818,4 @@ Next Topic: <a href="transactions.html">Transactions</a> </div> </body> -</html>
\ No newline at end of file +</html> diff --git a/user_guide/database/connecting.html b/user_guide/database/connecting.html index 309f2bc1a..b18088132 100644 --- a/user_guide/database/connecting.html +++ b/user_guide/database/connecting.html @@ -121,6 +121,8 @@ $this->load->database(<samp>$config</samp>);</code> <p>For information on each of these values please see the <a href="configuration.html">configuration page</a>.</p> +<p class="important"><strong>Note:</strong> For the PDO driver, $config['hostname'] should look like this: 'mysql:host=localhost'</p> + <p>Or you can submit your database values as a Data Source Name. DSNs must have this prototype:</p> <code>$dsn = 'dbdriver://username:password@hostname/database';<br /> 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.</p> $this->dbforge->add_column('table_name', $fields);<br /> <br /> // gives ALTER TABLE table_name ADD preferences TEXT</code></p> +<p>An optional third parameter can be used to specify which existing column to add the new column after.</p> +<p><code> +$this->dbforge->add_column('table_name', $fields, 'after_field'); +</code></p> <h2>$this->dbforge->drop_column()</h2> <p>Used to remove a column from a table. </p> <p><code>$this->dbforge->drop_column('table_name', 'column_to_drop');</code></p> diff --git a/user_guide/database/helpers.html b/user_guide/database/helpers.html index 6a8aba55b..be6c339b4 100644 --- a/user_guide/database/helpers.html +++ b/user_guide/database/helpers.html @@ -64,11 +64,11 @@ Query Helpers <h2>$this->db->insert_id()</h2> <p>The insert ID number when performing database inserts.</p> +<p class="important"><strong>Note:</strong> If using the PDO driver with PostgreSQL, this function requires a $name parameter, which specifies the appropriate sequence to check for the insert id.</p> <h2>$this->db->affected_rows()</h2> <p>Displays the number of affected rows, when doing "write" type queries (insert, update, etc.).</p> -<p>Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the -correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file.</p> +<p>Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file.</p> <h2>$this->db->count_all();</h2> diff --git a/user_guide/database/results.html b/user_guide/database/results.html index ec5f97762..a47e335cb 100644 --- a/user_guide/database/results.html +++ b/user_guide/database/results.html @@ -105,8 +105,8 @@ Query Results <br /> foreach ($query->result('User') as $user)<br /> {<br /> - echo $row->name; // call attributes<br /> - echo $row->reverse_name(); // or methods defined on the 'User' class<br /> + echo $user->name; // call attributes<br /> + echo $user->reverse_name(); // or methods defined on the 'User' class<br /> } </code> diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html index 8231c7e78..c80e3d106 100644 --- a/user_guide/database/utilities.html +++ b/user_guide/database/utilities.html @@ -183,14 +183,15 @@ $query = $this->db->query("SELECT * FROM mytable");<br /> echo $this->dbutil->csv_from_result($query); </code> -<p>The second and third parameters allows you to -set the delimiter and newline character. By default tabs are used as the delimiter and "\n" is used as a new line. Example:</p> +<p>The second, third, and fourth parameters allow you to +set the delimiter, newline, and enclosure characters respectively. By default tabs are used as the delimiter, "\n" is used as a new line, and a double-quote is used as the enclosure. Example:</p> <code> $delimiter = ",";<br /> $newline = "\r\n";<br /> +$enclosure = '"';<br /> <br /> -echo $this->dbutil->csv_from_result($query, $delimiter, $newline); +echo $this->dbutil->csv_from_result($query, $delimiter, $newline, $enclosure); </code> <p><strong>Important:</strong> This function will NOT write the CSV file for you. It simply creates the CSV layout. |