[英]Read the last inserted row
我有以下插入語句
global $dbUser;
global $dbPW;
$query = "INSERT INTO comments (post_id, text) VALUES (:post_id,:text)";
$db = new PDO('mysql:host=localhost;dbname=test', $dbUser, $dbPW);
$statement = $db -> prepare($query);
$statement -> execute(array(':post_id' => $postId, ':text' => $text));
我想在同一事務中讀取並返回插入的行。
我知道我可以得到
$ db-> lastInsertId('id')
但是我知道如何在PDO中進行事務,但是我無法通過上述准備好的語句(如何進行安全性IIRC的首選方法)來解決該問題。
謝謝!
您不需要在這里進行任何交易。
如果需要自動生成的ID,只需運行$ db-> lastInsertId()即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.