I need to perform multiple queries on a database table, basically my PHP script has to:
- insert into the table a new user storing his id, name, email;
- get the id of the newly created user using his email;
- associate the id with a key and a timestamp.
I am pretty new to PDO and my problem is I can’t figure out a smart way to get that one id without using a foreach, so basically my code is:
$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'];
1 Answer