我找到了一个解决方案,在使用MySQL中的单个查询更新行之前选择行的id:
UPDATE data_table
SET is_active = 0
WHERE token = 'some_token'
AND is_active = 1
AND @id := id;
SELECT @id;
但是我想找到一种方法来使用Doctrine来做同样的事情。我试过了:
$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();
但我只得到一个PDOException: SQLSTATE[HY000]: General error
,我找不到任何解决办法......
有什么想法吗?
根据解决方案from here,我找到了答案:
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();