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規則在命令行下工作的文件傳輸工具。 支持文件的上傳和下載。 這邊範例使用...

PDO bindParam 和 bindValue 差別在哪裡?

PDO bindParam ...

首先 bindParam 是綁定變數、bindValue  是綁定值。 以下範例: bindPara...

使用PHP mb_substr() 函式,擷取部分字串並記得使用UTF-8。

使用PHP mb_subst...

pexelsphotohello5 文字長度太長,一般來說我們可以使用DIV包住字串,再定義DIV的...

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