0

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();
Community
  • 1
  • 1
TiuSh
  • 145
  • 2
  • 9
  • Check this solution : [http://stackoverflow.com/questions/6541999/mysql-user-defined-variable-within-doctrine-and-symfony][1] [1]: http://stackoverflow.com/questions/6541999/mysql-user-defined-variable-within-doctrine-and-symfony – Lauri P Mar 18 '13 at 23:51
  • Thank you ! I found a solution using your link ! :) – TiuSh Mar 19 '13 at 10:38

0 Answers0