开发者

How to set one bit of a column in every record using Doctrine 1.2?

开发者 https://www.devze.com 2023-03-25 17:36 出处:网络
I\'m trying to build this SQL query: update shop_product set flags=flags^(flags&1024); Using Doctrine 1.2.

I'm trying to build this SQL query:

update shop_product set flags=flags^(flags&1024);

Using Doctrine 1.2.

I have tried these methods:

Doctrine_Query::create()
    ->update('Model_ShopProduct p')
    ->set('p.flags', 'p.flags^(p.flags&' . $flag);

also:

Doctrine_Qu开发者_开发问答ery::create()
    ->update('Model_ShopProduct p')
    ->set('p.flags', new Doctrine_Expression('p.flags^(p.flags&?'), $flag);

And many similar variations with no success. Please help mi with this one.


The simpliest way to achieve this is to salvage database connection from Doctrine and perfrom raw sql query on it, something like

$connection = Doctrine_Manager::getCurrentConnection()->getDbh();
//connection is an ordinary PDO object
$connection->query("update shop_product set flags=flags^(flags&1024);");

If you are not familiar with PDO, here is the documentation on PDO::query.

0

精彩评论

暂无评论...
验证码 换一张
取 消