• <tfoot id='39siu'></tfoot>

      <legend id='39siu'><style id='39siu'><dir id='39siu'><q id='39siu'></q></dir></style></legend>
    1. <small id='39siu'></small><noframes id='39siu'>

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

        如何判断 MySQL UPDATE 何时成功与实际更新的数据?

        时间:2024-08-22
      1. <tfoot id='T6jyh'></tfoot>
      2. <legend id='T6jyh'><style id='T6jyh'><dir id='T6jyh'><q id='T6jyh'></q></dir></style></legend>
        • <bdo id='T6jyh'></bdo><ul id='T6jyh'></ul>

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

                    <tbody id='T6jyh'></tbody>
                  <i id='T6jyh'><tr id='T6jyh'><dt id='T6jyh'><q id='T6jyh'><span id='T6jyh'><b id='T6jyh'><form id='T6jyh'><ins id='T6jyh'></ins><ul id='T6jyh'></ul><sub id='T6jyh'></sub></form><legend id='T6jyh'></legend><bdo id='T6jyh'><pre id='T6jyh'><center id='T6jyh'></center></pre></bdo></b><th id='T6jyh'></th></span></q></dt></tr></i><div id='T6jyh'><tfoot id='T6jyh'></tfoot><dl id='T6jyh'><fieldset id='T6jyh'></fieldset></dl></div>
                  本文介绍了如何判断 MySQL UPDATE 何时成功与实际更新的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何判断 MySQL UPDATE 何时成功与实际更新的数据?

                  How do I tell when a MySQL UPDATE was successful versus actually updated data?

                  示例:

                  TABLE
                  id    city_name
                  1     Union
                  2     Marthasville
                  

                  如果我运行以下命令:

                  $data = array('city_name', 'Marthasville');
                  
                  //update record 2 from Marthasville to the same thing, Marthasville. 
                  $this->db->where('id', 2);
                  $this->db->update('table', $data);
                  
                  if($this->db->affected_rows() > 0)
                  {
                      //I need it to return TRUE when the MySQL was successful even if nothing was actually updated.
                      return TRUE;
                  }else{
                      return FALSE;
                  }
                  

                  这将在每次 UPDATE 语句成功时返回 TRUE,但在没有实际更新行时返回 FALSE.

                  This will return TRUE every time the UPDATE statement is successful, but FALSE when no rows were actually updated.

                  我需要它在每次成功执行 UPDATE 语句时返回 TRUE,即使它实际上并没有更改任何记录.

                  I need it to return TRUE every time the UPDATE statement was successfully executed even if it doesn't actually change any records.

                  推荐答案

                  看看mysql_affected_rows()

                  它应该告诉您是否实际更新了任何内容,而不是没有成功更新任何内容并返回 true.

                  It should tell you if anything was actually updated as opposed to nothing was successfully updated resulting in a return of true.

                  php.net 说:

                  mysql_affected_rows()

                  mysql_affected_rows()

                  成功时返回受影响的行数,如果最后一个则返回 -1查询失败.

                  Returns the number of affected rows on success, and -1 if the last query failed.

                  您可以使用以下方法来实现您想要的结果:

                  You could use the following to achieve your desired results:

                  if($this->db->affected_rows() >= 0){ }
                  

                  这篇关于如何判断 MySQL UPDATE 何时成功与实际更新的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用带有 PDO 的数组更新多个 MySQL 表列 下一篇:如果行存在,则更新 MySQL 表的最快方法,否则插入.超过 2 个非唯一键

                  相关文章

                  <tfoot id='otkCo'></tfoot>
                • <small id='otkCo'></small><noframes id='otkCo'>

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