Loading...

PDO常用方法

Temperature: 0 °C

Mark ChangMark Chang
author_tools


PDO常用方法

PDO::query()
主要用於有記錄結果返回的操作(PDOStatement),特別是select操作。

PDO::exec()
主要是針對沒有結果集合返回的操作。如insert,update等操作。返回影響行數。

PDO::lastInsertId()
返回上次插入操作最後一條ID,但要注意:如果用insert into tb(col1,col2) values(v1,v2),(v11,v22)..的方式一次插入多條記錄,lastinsertid()返回的只是第一條(v1,v2)插入時的ID,而不是最後一條記錄插入的記錄ID。

PDOStatement::fetch()
是用來獲取一條記錄。配合while來遍歷。

PDOStatement::fetchAll()
是獲取所有記錄集到一個中。

PDOStatement::fetchcolumn([int column_indexnum])
用於直接訪問列,參數column_indexnum是該列在行中的從0開始索引值,但是,這個方法一次只能取得同一行的一列,只要執行一次,就跳到下一行。因此,用於直接訪問某一列時較好用,但要遍歷多列就用不上。

PDOStatement::rowcount()
適用於當用query("select ...")方法時,獲取記錄的條數。也可以用於預處理中。 $stmt-]rowcount();

PDOStatement::columncount()
適用於當用query("select ...")方法時,獲取記錄的列數。

https://innstory.com/story-PDO常用方法-1561
PHP

Prev
 PHP清空陣列函數

Next
分享_[MV]_SAY_YES__CHAGE_and_ASKA 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

.htaccess與RewriteEngine一起使用時500內部服務器錯誤

.htaccess與Rewr...

在某些情況下,可能未加載apache中的modrewrite模塊。 這時只需要執行以下指令就可以獲得...

CSS3濾鏡Filter的十種特效

CSS3濾鏡Filter的十...

CSS 濾鏡效果 Filters 主要是運用在圖片上,以實現一些特效。 grayscale 灰階 s...

修改php設定

修改php設定

pexelsphoto55 進入系統 用文字編輯軟體打開php.ini改變以下設定 disablef...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format