<i id='Zu9j6'><tr id='Zu9j6'><dt id='Zu9j6'><q id='Zu9j6'><span id='Zu9j6'><b id='Zu9j6'><form id='Zu9j6'><ins id='Zu9j6'></ins><ul id='Zu9j6'></ul><sub id='Zu9j6'></sub></form><legend id='Zu9j6'></legend><bdo id='Zu9j6'><pre id='Zu9j6'><center id='Zu9j6'></center></pre></bdo></b><th id='Zu9j6'></th></span></q></dt></tr></i><div id='Zu9j6'><tfoot id='Zu9j6'></tfoot><dl id='Zu9j6'><fieldset id='Zu9j6'></fieldset></dl></div>
      <tfoot id='Zu9j6'></tfoot>

        <bdo id='Zu9j6'></bdo><ul id='Zu9j6'></ul>
      <legend id='Zu9j6'><style id='Zu9j6'><dir id='Zu9j6'><q id='Zu9j6'></q></dir></style></legend>

      <small id='Zu9j6'></small><noframes id='Zu9j6'>

    1. Yii 中的更新查询

      Update query in Yii(Yii 中的更新查询)
      1. <small id='0521A'></small><noframes id='0521A'>

      2. <tfoot id='0521A'></tfoot>
      3. <i id='0521A'><tr id='0521A'><dt id='0521A'><q id='0521A'><span id='0521A'><b id='0521A'><form id='0521A'><ins id='0521A'></ins><ul id='0521A'></ul><sub id='0521A'></sub></form><legend id='0521A'></legend><bdo id='0521A'><pre id='0521A'><center id='0521A'></center></pre></bdo></b><th id='0521A'></th></span></q></dt></tr></i><div id='0521A'><tfoot id='0521A'></tfoot><dl id='0521A'><fieldset id='0521A'></fieldset></dl></div>
          <bdo id='0521A'></bdo><ul id='0521A'></ul>
          <legend id='0521A'><style id='0521A'><dir id='0521A'><q id='0521A'></q></dir></style></legend>
            <tbody id='0521A'></tbody>

                本文介绍了Yii 中的更新查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 Yii 中有一个要求,我必须根据某些条件更新一张表.我必须用 new_val = previous_value + new_val 更新列.但是代码没有按预期工作.

                I have one requirement in Yii where I have to update one table based on some condition. And I have to update the column with new_val = previous_value + new_val. But the code is not working as expected.

                我试过的代码是

                $update = Yii::app()->db->createCommand()
                ->update('tbl_post', array('star'=>('star' + 1),'total'=>('total' + $ratingAjax)),
                'id=:id',array(':id'=>$post_id));
                

                在正常查询中,查询将是

                In normal query the query will be

                UPDATE tbl_post set star= star + 1,total = total + '$ratingAjax' where id = 1
                

                有人知道错误在哪里吗?

                Anybody knows where is mistake?

                推荐答案

                尝试以下操作:

                $update = Yii::app()->db->createCommand()
                    ->update('tbl_post', 
                        array(
                            'star'=>new CDbExpression('star + 1'),
                            'total'=>new CDbExpression('total + :ratingAjax', array(':ratingAjax'=>$ratingAjax))
                        ),
                        'id=:id',
                        array(':id'=>$post_id)
                    );
                

                使用 CDbExpression 将允许您发送一个表达式来更新列值.

                Using CDbExpression will allow you to send an expression for what to update the column value to be.

                参见:http://www.yiiframework.com/doc/api/1.1/CDbCommand#更新细节

                和:http://www.yiiframework.com/doc/api/1.1/CDbExpression#__构造细节

                这篇关于Yii 中的更新查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <bdo id='ZeIxo'></bdo><ul id='ZeIxo'></ul>

                      <tfoot id='ZeIxo'></tfoot>
                        <tbody id='ZeIxo'></tbody>

                        • <legend id='ZeIxo'><style id='ZeIxo'><dir id='ZeIxo'><q id='ZeIxo'></q></dir></style></legend>

                          <small id='ZeIxo'></small><noframes id='ZeIxo'>

                          <i id='ZeIxo'><tr id='ZeIxo'><dt id='ZeIxo'><q id='ZeIxo'><span id='ZeIxo'><b id='ZeIxo'><form id='ZeIxo'><ins id='ZeIxo'></ins><ul id='ZeIxo'></ul><sub id='ZeIxo'></sub></form><legend id='ZeIxo'></legend><bdo id='ZeIxo'><pre id='ZeIxo'><center id='ZeIxo'></center></pre></bdo></b><th id='ZeIxo'></th></span></q></dt></tr></i><div id='ZeIxo'><tfoot id='ZeIxo'></tfoot><dl id='ZeIxo'><fieldset id='ZeIxo'></fieldset></dl></div>