Reputation: 107
There is a query
UPDATE users SET hash =: hash, num_try_incorrect_pass = 0
WHERE email =: email; SELECT * FROM users WHERE email =: email
First perform UPDATE
Next SELECT
How to do this with one request?
Upvotes: 0
Views: 193
Reputation: 3695
How about using stored procedures?
If you are looking for execute both queries from one code-statement you can define them as stored procedure in your database.
DELIMITER //
CREATE PROCEDURE ExecuteQueries(IN pEmail VARCHAR(50),
IN pHash VARCHAR(60))
BEGIN
UPDATE users SET hash=pHash, num_try_incorrect_pass = 0 WHERE email = pEmail;
SELECT * FROM users WHERE email = pEmail;
END //
DELIMITER ;
You can then execute both of these statements though your php code in this manner:
$stmt = $dbh->prepare("CALL ExecuteQueries($sEmail,$sHash)");
For more info: Getting Started with MySQL Stored Procedures
Upvotes: 4
Reputation: 2125
I'm not sure what you want.
You want to run a single query on your database to both update and select the updated row(s)? If so, this can't be done. You should consider creating a MySQL function to update and return a resultset with your latter query. Here's the docs on how to create functions and procedures with MySQL
Upvotes: 1