PHP Doctrine 1.2 SET 语句中的条件 IF 语句 [英] Conditional IF statement in a PHP Doctrine 1.2 SET statement

查看:37
本文介绍了PHP Doctrine 1.2 SET 语句中的条件 IF 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 SET 行找到正确的语法:

I would like find the correct syntax for the SET line:

Doctrine_Query::create()
->update('Media m')
->set('m.fallback IF(m.id = ?, 1, 0)', $id)  <-- not correct
->execute();

感谢您的帮助!

推荐答案

我认为这可以通过两个查询来完成:

I think that could be done with two queries:

Doctrine_Query::create()
    ->update('Media m')
    ->set('m.fallback', 1)
    ->where('m.id = ?', $id)
    ->execute();

Doctrine_Query::create()
    ->update('Media m')
    ->set('m.fallback', 0)
    ->where('m.id != ?', $id)
    ->execute();

我不知道它是否适合您,但至少可以满足您的需求.可能无法开箱即用,因为我手头没有 Doctrine 1.2,所以无法对此进行测试.但我认为这个想法很明确:)

I don't know if it suits you, but at least that will do what you want. May not work out of the box, as I don't have Doctrine 1.2 at hand, so can't test this. But I think the idea is clear :)

这篇关于PHP Doctrine 1.2 SET 语句中的条件 IF 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆