I found a solution to select the id of a row before it's updated using a single query in MySQL :
UPDATE data_table
SET is_active = 0
WHERE token = 'some_token'
AND is_active = 1
AND @id := id;
SELECT @id;
But I would like to find a way to do the same using Doctrine. I tried :
$pdo = Doctrine_Manager::getInstance()->getCurrentConnection();
$res = $pdo->execute("
UPDATE data_table
SET is_active = 0
WHERE token = 'some_token'
AND is_active = 1
AND @id := id;
SELECT @id;
")->fetchAll();
But I only get a PDOException: SQLSTATE[HY000]: General error
and I don't find any workaround ...
Any ideas ?
Based on the solution from here I found an answer :
Doctrine_Manager::getInstance()->getCurrentConnection()->standaloneQuery("
UPDATE data_table
SET is_active = 0
WHERE token = 'some_token'
AND is_active = 1
AND @id := id;
");
$data = DataTable::getInstance()->createQuery('d')->where('id = @id')->fetchOne();