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

Android UI設計距離課題

Android UI設計距離...

layoutmarginTop指定該屬性所在控件距離上方的位置空間。 layoutmarginBot...

使用PHP取得目前網址方式

使用PHP取得目前網址方式

pexelsphoto55 使用PHP取得網址相關的方式有下列幾種: $SERVER["R...

判斷字串是否存在於內容中

判斷字串是否存在於內容中

searchphoto5 以下範例~ 搜尋 If you are lucky enough to b...

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