天天看點

CI中擷取讀操作的結果集行數+擷取寫操作的影響行數

CI中的方法:

讀操作,擷取行數:

該函數将會傳回目前請求的行數。在本例子中, $query 表示目前 SQL 所産生的請求結果對象:

<code>$query = $this-&gt;db-&gt;query('SELECT * FROM my_table'); echo $query-&gt;num_rows(); </code>

寫操作,擷取影響的行數:

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 功能是打開的但可以在資料庫驅動檔案中關閉它。 

如何聯系我:【萬裡虎】www.bravetiger.cn

【QQ】3396726884 (咨詢問題100元起,幫助解決問題500元起)

【部落格】http://www.cnblogs.com/kenshinobiy/