本文介紹了使用插入 PDO MySQL 獲取插入 ID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在掌握 PDO 的基礎知識.
Im getting to grips with the basics of PDO.
但是我試圖獲取插入行的 id,我使用:
However Im trying to get the id of the inserted row, Im using:
$query = $system->db->prepare("INSERT INTO {$this->_table} (name,description) VALUES (:name,:description)");
$query->execute(array('name'=>$name,'description'=>$description));
我遇到的教程是關于交易的,但我沒有使用交易!
The tutorials I have come across are regarding transactions, however I am not using transactions!
推薦答案
您可能正在尋找 lastInsertId.返回最后插入的行或序列值的 ID".
You're probably looking for lastInsertId. "Returns the ID of the last inserted row or sequence value".
$insertedId = $system->db->lastInsertId() ;
這篇關于使用插入 PDO MySQL 獲取插入 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!