I'm using pdo and I have a query like this
$stmt=$db->query("SET @update_id := 0;
UPDATE table SET column = something, id = (SELECT @update_id := id)
WHERE condition
LIMIT 1;
SELECT @update_id;");
It is supposed to update a row and return the id.
I'm sure the query itself is working because I ran it in phpmyadmin and it returned a column named @updated_id with the value of the updated row like this:
| @updated_id |
|------------------|
| *correct id* |
I want to fetch the value of @updated_id and store it in a php variable.
I tried $stmt->fetchColumn();
and $stmt->fetchColumn();
but I get SQLSTATE[HY000]: General error
.
I've been searching for something to work but I can't find anything.
so anybody knows how to store the value of @updated_id in a php variable?
thanks