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

      1. <small id='RCYEw'></small><noframes id='RCYEw'>

      2. <tfoot id='RCYEw'></tfoot>

        PHP/MySQL - “开始...提交"不工作

        PHP/MySQL - quot;BEGIN...COMMITquot; Not Working(PHP/MySQL - “开始...提交不工作)
        <legend id='CuFaA'><style id='CuFaA'><dir id='CuFaA'><q id='CuFaA'></q></dir></style></legend>
            • <bdo id='CuFaA'></bdo><ul id='CuFaA'></ul>
                <tbody id='CuFaA'></tbody>

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

                  <tfoot id='CuFaA'></tfoot>
                  本文介绍了PHP/MySQL - “开始...提交"不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找一种在单个查询中将数据插入两个数据库表的方法,这样如果一个失败,则不会保存(我不想要孤立的数据).我遇到了一个 Stack Overflow 问题,该问题向我展示了如何使用 BEGIN...COMMIT 来完成此操作,但它根本不起作用.

                  I was searching for a way to insert data into two database tables in a single query in such a way that if one failed, neither saved (I don't want orphaned data). I came across a Stack Overflow question that showed me how to use BEGIN...COMMIT to accomplish this, but it simply is not working.

                  这是我设置的查询:

                  $query = "BEGIN;
                              INSERT INTO content_subpages (title, url_referer) VALUES ('$pagetitle','$url_referer');
                              INSERT INTO ccm_main_menu (sub_item, sub_item_link,sub_item_sort_order) VALUES ('$pagetitle','$url_referer','$newsort');
                              COMMIT;";
                  mysql_query($query) or die (mysql_error());
                  

                  我收到以下错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'INSERT INTO content_subpages (title, url_referer) VALUES ('TESTING','testing') 附近使用的正确语法;' 在第 2 行

                  这是我第一次使用 BEGIN...COMMIT,所以我可能做错了什么是合理的,但我遵循了我提到的 Stack Overflow 问题的选定答案给出的 SQL Fiddle 示例的语法(http://stackoverflow.com/questions/12649706/mysql-insert-into-multiple-tables-in-same-query-with-begincommit),但它仍然无法正常工作.

                  This is my first time using BEGIN...COMMIT, so it's reasonable that I might be doing something wrong, but I followed the syntax of the SQL Fiddle example given by the selected answer to the Stack Overflow question I mentioned (http://stackoverflow.com/questions/12649706/mysql-insert-into-multiple-tables-in-same-query-with-begincommit), but it still won't work.

                  如果我可以在没有 BEGIN...COMMIT 的情况下轻松实现全有或全无"多重 INSERT 结果,那将是一个可以接受的解决方案.

                  If I can easily achieve the "all-or-nothing" multiple INSERT result without BEGIN...COMMIT, that would be an acceptable solution.

                  提前致谢

                  推荐答案

                  尝试将这些行分成多个 php 语句:

                  Try breaking the lines into multiple php statements:

                  $query = "BEGIN";
                  mysql_query($query) or die (mysql_error());
                  $query = "INSERT INTO content_subpages (title, url_referer) VALUES ('$pagetitle','$url_referer')";
                  mysql_query($query) or die (mysql_error());
                  
                  $query = "INSERT INTO ccm_main_menu (sub_item, sub_item_link,sub_item_sort_order) VALUES ('$pagetitle','$url_referer','$newsort')";
                  mysql_query($query) or die (mysql_error())
                  
                  $query = "COMMIT";
                  mysql_query($query) or die (mysql_error());
                  

                  这篇关于PHP/MySQL - “开始...提交"不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                  Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                  Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                  quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                  Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                  Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)

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

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

                            <tfoot id='fEewu'></tfoot>