blob: b0a5ce97b9f3665d4079b7a2e383ebbee70ab216 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001######################
2Query Helper Functions
3######################
4
5$this->db->insert_id()
6=======================
7
8The insert ID number when performing database inserts.
9
10.. note:: If using the PDO driver with PostgreSQL, this function requires
11 a $name parameter, which specifies the appropriate sequence to check
12 for the insert id.
13
14$this->db->affected_rows()
15===========================
16
17Displays the number of affected rows, when doing "write" type queries
18(insert, update, etc.).
19
20.. note:: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database
21 class has a small hack that allows it to return the correct number of
22 affected rows. By default this hack is enabled but it can be turned off
23 in the database driver file.
24
25$this->db->count_all();
26========================
27
28Permits you to determine the number of rows in a particular table.
29Submit the table name in the first parameter. Example::
30
31 echo $this->db->count_all('my_table'); // Produces an integer, like 25
32
33$this->db->platform()
34=====================
35
36Outputs the database platform you are running (MySQL, MS SQL, Postgres,
37etc...)::
38
39 echo $this->db->platform();
40
41$this->db->version()
42====================
43
44Outputs the database version you are running::
45
46 echo $this->db->version();
47
48$this->db->last_query();
49=========================
50
51Returns the last query that was run (the query string, not the result).
52Example::
53
54 $str = $this->db->last_query(); // Produces: SELECT * FROM sometable....
55
56The following two functions help simplify the process of writing
57database INSERTs and UPDATEs.
58
59$this->db->insert_string();
60============================
61
62This function simplifies the process of writing database inserts. It
63returns a correctly formatted SQL insert string. Example::
64
65 $data = array('name' => $name, 'email' => $email, 'url' => $url); $str = $this->db->insert_string('table_name', $data);
66
67The first parameter is the table name, the second is an associative
68array with the data to be inserted. The above example produces::
69
70 INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com')
71
72Note: Values are automatically escaped, producing safer queries.
73
74$this->db->update_string();
75============================
76
77This function simplifies the process of writing database updates. It
78returns a correctly formatted SQL update string. Example::
79
80 $data = array('name' => $name, 'email' => $email, 'url' => $url); $where = "author_id = 1 AND status = 'active'"; $str = $this->db->update_string('table_name', $data, $where);
81
82The first parameter is the table name, the second is an associative
83array with the data to be updated, and the third parameter is the
84"where" clause. The above example produces::
85
86 UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url = 'example.com' WHERE author_id = 1 AND status = 'active'
87
88Note: Values are automatically escaped, producing safer queries.