我需要在数据库表上执行多个查询,基本上我的PHP脚本必须:
我是PDO的新手,我的问题是我无法找到一个聪明的方法来获得id
而不使用foreach
,所以基本上我的代码是:
$query = "INSERT INTO users(name, surname, email) VALUES('" . $name . "', '" . $surname . "', '" . $email . "')";
$this->dbconn->query($query);
$query = "SELECT id FROM users WHERE email='" . $email . "'";
$data = $this->dbconn->query($query);
$id = $data['id'];
答案 0 :(得分:2)
$query = "INSERT INTO users(name, surname, email) VALUES('" . $name . "', '" . $surname . "', '" . $email . "')";
$this->dbconn->query($query);
$id = $this->dbconn->lastInsertId();