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

  • <small id='u6VPJ'></small><noframes id='u6VPJ'>

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

        在 Yii 中更新查询

        时间:2024-08-22

          <tbody id='PtCOa'></tbody>

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

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

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

                  本文介绍了在 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
                  

                  有人知道错在哪里吗?

                  推荐答案

                  试试以下:

                  $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#update-detail

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

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

                  上一篇:如何随机一个零前导字符串字段mysql 下一篇:在 Codeigniter 中更新多行

                  相关文章

                    <bdo id='8o5gJ'></bdo><ul id='8o5gJ'></ul>

                  <small id='8o5gJ'></small><noframes id='8o5gJ'>

                  1. <legend id='8o5gJ'><style id='8o5gJ'><dir id='8o5gJ'><q id='8o5gJ'></q></dir></style></legend>

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