summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/database/examples.rst
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2018-01-13 12:57:11 +0100
committerAndrey Andreev <narf@devilix.net>2018-01-13 12:57:11 +0100
commit02a0518e1c56ba3506f370362ac5ebdb8a138312 (patch)
tree8b4684192b403dcae17d298eb4fc9e7ab001acad /user_guide_src/source/database/examples.rst
parentf0b9735d5857e6c07c8f5824b13cff4828db3cfe (diff)
[ci skip] 3.1.7 release
Diffstat (limited to 'user_guide_src/source/database/examples.rst')
-rw-r--r--user_guide_src/source/database/examples.rst119
1 files changed, 0 insertions, 119 deletions
diff --git a/user_guide_src/source/database/examples.rst b/user_guide_src/source/database/examples.rst
deleted file mode 100644
index 5fd7fccfa..000000000
--- a/user_guide_src/source/database/examples.rst
+++ /dev/null
@@ -1,119 +0,0 @@
-##################################
-Database Quick Start: Example Code
-##################################
-
-The following page contains example code showing how the database class
-is used. For complete details please read the individual pages
-describing each function.
-
-Initializing the Database Class
-===============================
-
-The following code loads and initializes the database class based on
-your :doc:`configuration <configuration>` settings::
-
- $this->load->database();
-
-Once loaded the class is ready to be used as described below.
-
-Note: If all your pages require database access you can connect
-automatically. See the :doc:`connecting <connecting>` page for details.
-
-Standard Query With Multiple Results (Object Version)
-=====================================================
-
-::
-
- $query = $this->db->query('SELECT name, title, email FROM my_table');
-
- foreach ($query->result() as $row)
- {
- echo $row->title;
- echo $row->name;
- echo $row->email;
- }
-
- echo 'Total Results: ' . $query->num_rows();
-
-The above result() function returns an array of **objects**. Example:
-$row->title
-
-Standard Query With Multiple Results (Array Version)
-====================================================
-
-::
-
- $query = $this->db->query('SELECT name, title, email FROM my_table');
-
- foreach ($query->result_array() as $row)
- {
- echo $row['title'];
- echo $row['name'];
- echo $row['email'];
- }
-
-The above result_array() function returns an array of standard array
-indexes. Example: $row['title']
-
-Standard Query With Single Result
-=================================
-
-::
-
- $query = $this->db->query('SELECT name FROM my_table LIMIT 1');
- $row = $query->row();
- echo $row->name;
-
-The above row() function returns an **object**. Example: $row->name
-
-Standard Query With Single Result (Array version)
-=================================================
-
-::
-
- $query = $this->db->query('SELECT name FROM my_table LIMIT 1');
- $row = $query->row_array();
- echo $row['name'];
-
-The above row_array() function returns an **array**. Example:
-$row['name']
-
-Standard Insert
-===============
-
-::
-
- $sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")";
- $this->db->query($sql);
- echo $this->db->affected_rows();
-
-Query Builder Query
-===================
-
-The :doc:`Query Builder Pattern <query_builder>` gives you a simplified
-means of retrieving data::
-
- $query = $this->db->get('table_name');
-
- foreach ($query->result() as $row)
- {
- echo $row->title;
- }
-
-The above get() function retrieves all the results from the supplied
-table. The :doc:`Query Builder <query_builder>` class contains a full
-compliment of functions for working with data.
-
-Query Builder Insert
-====================
-
-::
-
- $data = array(
- 'title' => $title,
- 'name' => $name,
- 'date' => $date
- );
-
- $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
-