查詢輔助函數(shù)
$this->db->insert_id()
這個ID號是執(zhí)行數(shù)據(jù)插入時的ID。
$this->db->affected_rows()
Displays the number of affected rows, when doing "write\" type queries (insert, update, etc.).
當(dāng)執(zhí)行寫入操作(insert,update等)的查詢后,顯示被影響的行數(shù)。
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.
注意:在 MySQL 中“DELETE FROM TABLE”的被影響行數(shù)將會返回 0。database 類有一個小 hack 允許返回正確的被影響的行數(shù)。默認(rèn)情況下這個 hack 功能是打開的但可以在數(shù)據(jù)庫驅(qū)動文件中關(guān)閉它。
$this->db->count_all();
Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:
計算出指定表的總行數(shù)并返回。在第一個參數(shù)中寫入被提交的表名。例如:
echo $this->db->count_all('my_table');
// Produces an integer, like 25
$this->db->platform()
Outputs the database platform you are running (MySQL, MS SQL, Postgres, etc...):
輸出系統(tǒng)使用的數(shù)據(jù)庫平臺(MySQL, MS SQL, Postgres……)
echo $this->db->platform();
$this->db->version()
Outputs the database version you are running:
輸出系統(tǒng)正在運行的數(shù)據(jù)庫版本號
echo $this->db->version();
$this->db->last_query();
Returns the last query that was run (the query string, not the result). Example:
返回最后運行的查詢(是查詢語句,不是查詢結(jié)果)
$str = $this->db->last_query();
// Produces: SELECT * FROM sometable....
The following two functions help simplify the process of writing database INSERTs and UPDATEs.
下面的兩個函數(shù)簡化了寫入數(shù)據(jù)庫的insert和update函數(shù)。
$this->db->insert_string();
This function simplifies the process of writing database inserts. It returns a correctly formatted SQL insert string. Example:
這個函數(shù)簡化了寫入數(shù)據(jù)庫的insert函數(shù)。它返回一個標(biāo)準(zhǔn)的SQL insert字符串。例如:
$data = array('name' => $name, 'email' => $email, 'url' => $url);
$str = $this->db->insert_string('table_name', $data);
The first parameter is the table name, the second is an associative array with the data to be inserted. The above example produces:
第一個參數(shù)是表名,第二個是被插入數(shù)據(jù)的聯(lián)合數(shù)組,上面的例子生成的效果為:
INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com')
Note: Values are automatically escaped, producing safer queries.
注解:被插入的數(shù)據(jù)會被自動轉(zhuǎn)換和過濾,生成安全的查詢語句。
$this->db->update_string();
This function simplifies the process of writing database updates. It returns a correctly formatted SQL update string. Example:
這個函數(shù)簡化了寫入數(shù)據(jù)庫的update函數(shù)。它返回一個標(biāo)準(zhǔn)的SQL update字符串。例如:
$data = array('name' => $name, 'email' => $email, 'url' => $url);
$where = "author_id = 1 AND status = 'active'";
$str = $this->db->update_string('table_name', $data, $where);
The first parameter is the table name, the second is an associative array with the data to be updated, and the third parameter is the "where" clause. The above example produces:
第一個參數(shù)是表名,第二個是被更新數(shù)據(jù)的關(guān)聯(lián)數(shù)組,第三個參數(shù)是“where”參數(shù)。上面的例子生成的效果為:
UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url = 'example.com' WHERE author_id = 1 AND status = 'active'
Note: Values are automatically escaped, producing safer queries.
注解:被插入的數(shù)據(jù)會被自動轉(zhuǎn)換和過濾,生成安全的查詢語句。
?