***CI查询辅助函数:insert_id()、affected_rows()
查詢輔助函數
$this->db->insert_id()
這個ID號是執行數據插入時的ID。
$this->db->affected_rows()
Displays the number of affected rows, when doing "write\" type queries (insert, update, etc.).
當執行寫入操作(insert,update等)的查詢后,顯示被影響的行數。
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”的被影響行數將會返回 0。database 類有一個小 hack 允許返回正確的被影響的行數。默認情況下這個 hack 功能是打開的但可以在數據庫驅動文件中關閉它。
$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:
計算出指定表的總行數并返回。在第一個參數中寫入被提交的表名。例如: 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...):
輸出系統使用的數據庫平臺(MySQL, MS SQL, Postgres……)
echo $this->db->platform();
$this->db->version()
Outputs the database version you are running:
輸出系統正在運行的數據庫版本號 echo $this->db->version();
$this->db->last_query();
Returns the last query that was run (the query string, not the result). Example:
返回最后運行的查詢(是查詢語句,不是查詢結果)
$str = $this->db->last_query();
// Produces: SELECT * FROM sometable....
The following two functions help simplify the process of writing database INSERTs and UPDATEs.
下面的兩個函數簡化了寫入數據庫的insert和update操作。
$this->db->insert_string();
This function simplifies the process of writing database inserts. It returns a correctly formatted SQL insert string. Example:
這個函數簡化了寫入數據庫的insert函數。它返回一個標準的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:
第一個參數是表名,第二個是被插入數據的聯合數組,上面的例子生成的效果為: INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com')
Note: Values are automatically escaped, producing safer queries.
注解:被插入的數據會被自動轉換和過濾,生成安全的查詢語句。
$this->db->update_string();
This function simplifies the process of writing database updates. It returns a correctly formatted SQL update string. Example:
這個函數簡化了寫入數據庫的update操作。它返回一條格式正確的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:
第一個參數是表名,第二個是被更新數據的關聯數組,第三個參數是“where”子句。上面的例子生成的效果為: 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.
注解:被插入的數據會被自動轉換和過濾,生成安全的查詢語句。
總結
以上是生活随笔為你收集整理的***CI查询辅助函数:insert_id()、affected_rows()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 西门子 PLC 和 AB罗克韦尔 PLC
- 下一篇: python-snap7使用说明