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

PHP使用array_product()函數求得陣列中的乘積

PHP使用array_pro...

arrayproduct()是PHP中的一個內建函數,可以返回陣列中所有元素的乘積。 例如 $arr...

利用 .htaccess 限制可瀏覽ip來源

利用 .htaccess 限...

要如何限制某個資料夾內容只能給特定IP讀取? 這個部分其實可以透過.htaccess快速實現~ 首先...

PHP查詢陣列中是否存在特定字串in_array() 函數

PHP查詢陣列中是否存在特定...

使用函數inarray() ,適用版本(PHP , PHP 5, PHP , PHP ) 使用方式:...

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