?
This document uses PHP Chinese website manual Release
$這個 - > DB-> INSERT_ID()
執(zhí)行數(shù)據(jù)庫插入時的插入ID號。
注
如果在PostgreSQL中使用PDO驅動程序,或者使用Interbase驅動程序,則此函數(shù)需要一個$name參數(shù),該參數(shù)指定檢查插入id的適當順序。
$this - > DB-> affected_rows()
顯示執(zhí)行“寫入”類型查詢(插入,更新等)時受影響的行數(shù)。
注
在MySQL中,“DELETE FROM TABLE”返回0個受影響的行。數(shù)據(jù)庫類有一個小黑客,它允許它返回正確數(shù)量的受影響的行。默認情況下,此hack已啟用,但可以在數(shù)據(jù)庫驅動程序文件中關閉。
$這個 - > DB-> last_query()
返回運行的最后一個查詢(查詢字符串,而不是結果)。例:
$str = $this->db->last_query();// Produces: SELECT * FROM sometable....
注
禁用數(shù)據(jù)庫配置中的save_queries設置將使此功能無效。
$這個 - > DB-> count_all()
允許您確定特定表中的行數(shù)。在第一個參數(shù)中提交表名。例子:
echo $this->db->count_all('my_table');// Produces an integer, like 25
$這個 - > DB->platform()
輸出您正在運行的數(shù)據(jù)庫平臺(MySQL,MS SQL,Postgres等):
echo $this->db->platform();
$this - > DB->version()
輸出正在運行的數(shù)據(jù)庫版本:
echo $this->db->version();
$this - > DB-> insert_string()
該函數(shù)簡化了寫入數(shù)據(jù)庫插入的過程。它返回格式正確的SQL插入字符串。例子:
$data = array('name' => $name, 'email' => $email, 'url' => $url);$str = $this->db->insert_string('table_name', $data);
第一個參數(shù)是表名,第二個參數(shù)是要插入的數(shù)據(jù)的關聯(lián)數(shù)組。上面的例子產生了:
INSERT INTO table_name (name, email, url) VALUES ('Rick', '[email protected]', 'example.com')
注
值會自動轉義,從而產生更安全的查詢。
$this - > DB-> update_string()
該函數(shù)簡化了編寫數(shù)據(jù)庫更新的過程。它返回格式正確的SQL更新字符串。例子:
$data = array('name' => $name, 'email' => $email, 'url' => $url); $where = "author_id = 1 AND status = 'active'"; $str = $this->db->update_string('table_name', $data, $where);
第一個參數(shù)是表名,第二個參數(shù)是要更新的數(shù)據(jù)的關聯(lián)數(shù)組,第三個參數(shù)是“WHERE”子句。上面的例子產生了:
UPDATE table_name SET name = 'Rick', email = '[email protected]', url = 'example.com' WHERE author_id = 1 AND status = 'active'
注
值會自動轉義,從而產生更安全的查詢。