本文介紹了使用插入 PDO MySQL 獲取插入 ID的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在掌握 PDO 的基礎(chǔ)知識.
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));
我遇到的教程是關(guān)于交易的,但我沒有使用交易!
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() ;
這篇關(guān)于使用插入 PDO MySQL 獲取插入 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!