1. <small id='9FiYl'></small><noframes id='9FiYl'>

        <bdo id='9FiYl'></bdo><ul id='9FiYl'></ul>
      <tfoot id='9FiYl'></tfoot>

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

        PHP MYSQL UPDATE 如果存在或 INSERT 如果不存在?

        时间:2024-08-23

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

              • <small id='5LtZM'></small><noframes id='5LtZM'>

                  <tfoot id='5LtZM'></tfoot>
                  本文介绍了PHP MYSQL UPDATE 如果存在或 INSERT 如果不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我不知道这是否正确.我有一个类,如果字段当前存在,我想更新数据库,如果不存在则插入.复杂之处在于我正在加入 3 个表(set_colors、school_art、baseimage)

                  任何帮助都会非常棒.

                  这是我所拥有的:

                  公共函数 set_layer_colors($value) {全局$db;$result_array = mysql_query("如果存在(SELECT * FROM set_colors WHERE school_art_id = '{$value}')更新 set_colors (school_art_id, baseimage_id, sub_folder, layer)选择 school_art.id、baseimage.id、baseimage.sub_folder、baseimage.layerFROM school_art在 baseimage.base_folder = school_art.series_code 上加入 baseimageWHERE baseimage.image_type = 'B' ORDER BY school_art.id别的INSERT INTO set_colors (school_art_id, baseimage_id, sub_folder, layer)选择 school_art.id、baseimage.id、baseimage.sub_folder、baseimage.layerFROM school_art在 baseimage.base_folder = school_art.series_code 上加入 baseimageWHERE baseimage.image_type = 'B' ORDER BY school_art.id");返回 $result_array;}

                  解决方案

                  相信你正在寻找以下语法:

                  INSERT INTO <table>(字段 1,字段 2,字段 3,...)值('value1','value2','value3',...)重复密钥更新field1='value1', field2='value2', field3='value3', ...

                  <块引用>

                  注意:使用ON DUPLICATE KEY UPDATE,如果行被插入<,则每行受影响的行值为1/em> 作为新行,2 如果现有行已更新0 如果现有行设置为其当前值.

                  MySQL 文档:INSERT ...ON DUPLICATE KEY UPDATE 语句

                  I have no idea if this is even remotely correct. I have a class where I would like to update the database if the fields currently exist or insert if they do not. The complication is that I am doing a joining 3 tables (set_colors, school_art, baseimage)

                  Any help would be really great.

                  Here is what I have:

                  public function set_layer_colors($value) {
                      global $db;
                  
                      $result_array = mysql_query("
                      IF EXISTS(SELECT * FROM set_colors WHERE school_art_id = '{$value}')
                  
                        UPDATE set_colors (school_art_id, baseimage_id, sub_folder, layer)
                          SELECT school_art.id, baseimage.id, baseimage.sub_folder, baseimage.layer
                          FROM school_art 
                          JOIN baseimage ON baseimage.base_folder = school_art.series_code 
                          WHERE baseimage.image_type = 'B' ORDER BY school_art.id 
                  
                      ELSE
                  
                       INSERT INTO set_colors (school_art_id, baseimage_id, sub_folder, layer)
                          SELECT school_art.id, baseimage.id, baseimage.sub_folder, baseimage.layer
                          FROM school_art 
                          JOIN baseimage ON baseimage.base_folder = school_art.series_code 
                          WHERE baseimage.image_type = 'B' ORDER BY school_art.id 
                          ");
                  
                      return $result_array;
                  }
                  

                  解决方案

                  I believe you are looking for the following syntax:

                  INSERT INTO <table> (field1, field2, field3, ...) 
                  VALUES ('value1', 'value2','value3', ...)
                  ON DUPLICATE KEY UPDATE
                  field1='value1', field2='value2', field3='value3', ...
                  

                  Note: With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values.

                  MySQL Documentation: INSERT ... ON DUPLICATE KEY UPDATE Statement

                  这篇关于PHP MYSQL UPDATE 如果存在或 INSERT 如果不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    • <tfoot id='7aahR'></tfoot>
                    • <legend id='7aahR'><style id='7aahR'><dir id='7aahR'><q id='7aahR'></q></dir></style></legend>

                      <small id='7aahR'></small><noframes id='7aahR'>

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

                        • <bdo id='7aahR'></bdo><ul id='7aahR'></ul>