日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

***CI查询辅助函数:insert_id()、affected_rows()

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ***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()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。