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

使用curl執行POST請求

使用curl執行POST請求...

curl命令是一個利用URL規則在命令行下工作的文件傳輸工具。 支持文件的上傳和下載。 這邊範例使用...

Format JavaScript Date to yyyy-mm-dd

Format JavaScr...

timecalendar5 JavaScript將Sun May ,轉換成yyyymmdd func...

如何將mysql table auto_increment重設

如何將mysql table...

photo555 資料表裡的資料加加減減,一不小心突然驚覺當初的欄位長度設定的不夠⊙⊙ 當然,你可以...

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