[英]undefined last inserted id
I need to get last inserted id 我需要获取最后插入的ID
$stmt = $db->query("SELECT LAST_INSERT_ID();");
$row = $stmt->fetch();
echo $row['id'];
js JS
success: function(data) {
console.log(data);
}
Result: undefined
! 结果:
undefined
!
You must assign the proper alias 您必须分配适当的别名
$stmt = $db->query("SELECT LAST_INSERT_ID() as id;");
$row = $stmt->fetch();
echo $row['id'];
otherwise echo $row['id'] is empty 否则echo $ row ['id']为空
LAST_INSERT_ID() returns the last id from a previous insert statement. LAST_INSERT_ID()返回前一个插入语句的最后一个ID。 If you want the most recently inserted record and are using Auto Increment Prime keys, you can use the code below:
如果您想要最近插入的记录并且正在使用“自动增量”主键,则可以使用以下代码:
SELECT MAX( id ) FROM table tablename;
If you need to know what the NEXT id will be, you can get this from INFORMATION_SCHEMA 如果您需要知道NEXT ID是什么,可以从INFORMATION_SCHEMA获取
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tablename'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.