dongzhi7641 2012-05-23 14:44
浏览 12
已采纳

在zend框架中使用LIMIT进行更新[重复]

Possible Duplicate:
How do I add a limit to update-query in Zend Framework?

I would like to do a update and place LIMIT 1 as precaution. Here is my code:

$vals = array();
$vals['status'] = 'closed';
$where = $write->quoteInto('id =?', $orderID);

$write->update("order", $vals ,$where);

Where can i add a LIMIT into this query?

(looks like has been asked in the past but i hope someone out there has the answer)

  • 写回答

3条回答 默认 最新

  • doukuang1950 2012-05-24 10:10
    关注

    It looks like you're using Zend_Db_Adapter to perform your queries so I'm not sure you can do what I do, anyway here goes.
    I usually use the Zend_Db_Table_Row save() method to insert and update records, however I also use the DbTable models to provide access to the Table and Table_Row abstract api's.

    public function save(Music_Model_Artist $artist) {
            //if id is not null
            if (!is_null($artist->id)) {
                //find row, uses fetchRow() so will return NULL if not found
                $row = $this->findById($artist->id);
                $row->id = $artist->id;
            } else {
                //if ID is null create new row
                $row = $this->_getGateway()->createRow();
            }
            //assign data to row
            $row->name = $artist->name;
            //save new row or update
            $row->save();
            //return the row, in case I need it for something else
            return $row;
        }
    

    what this amounts to is that if I include and ID in the data array (or in this case an entity object) the row will be updated and if there is no ID in the object a new row will be created.

    If your curious here's how I __construct the class:

    public function __construct(Zend_Db_Table_Abstract $tableGateway = NULL) {
            //pass in concrete DbTable Model, parent alts to using table name string to construct class
            $this->_tableGateway = new Application_Model_DbTable_Artist();
            parent::__construct($tableGateway);
        }
    

    Hope this provides some help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器