这就是我所拥有的:
$stmt = $handler->prepare('SELECT id FROM users');
$stmt->execute();
$id = $handler->lastInsertId();
echo $id;
所以,我希望结果是“有$ id注册用户”。
答案 0 :(得分:2)
您永远不需要从表格中选择“最后一个ID”。每当你认为自己需要它时,你需要别的东西。例如,“Last id”与注册的用户数无关。相反,您必须计算用户:
$count = $handler->query('SELECT count(id) FROM users')->fetchColumn();
echo "There is $count registered users";
答案 1 :(得分:0)
PDO::lastInsertId
- 返回最后插入的行或序列值的ID - https://secure.php.net/manual/en/pdo.lastinsertid.php。
您想要的是注册用户的计数,请参阅Row count with PDO。
要检索最后插入的ID或序列值,请参阅PDO get the last ID inserted。