我做错了什么,在第一条语句将它插入我的表后,我试图从表中获取最后一个 record_id。我似乎只打印了用于显示最后一个 id 的代码?
SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))";
代码在这里
else {
echo 'Record added';
$sql = "INSERT INTO sheet_tbl (site_id, eventdate, eventtime, username, additionalvolunteers) VALUES ('$_POST[site_id]','$_POST[eventdate]','$_POST[eventtime]', '$username','$_POST[additionalvolunteers]')";
echo $sql; //Just so I can see what is getting sent
$result = pg_query($sql);
$sheet_id_pull = "SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))";
echo $sheet_id_pull; //This is where im having the issue with the above line.
}
最佳答案
也许
echo pg_query($sheet_id_pull);
代替
echo $sheet_id_pull;
或者
$sheet_id_pull = pg_query("SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))");
echo $sheet_id_pull;
另请阅读 this
问题。它有更好的方法来获取插入的 ID。
关于postgresql - SELECT CURRVAL (pg_get_serial_sequence 我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17876809/