<legend id='O11s3'><style id='O11s3'><dir id='O11s3'><q id='O11s3'></q></dir></style></legend>
    1. <tfoot id='O11s3'></tfoot>
    2. <small id='O11s3'></small><noframes id='O11s3'>

      • <bdo id='O11s3'></bdo><ul id='O11s3'></ul>

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

      PHP Try and Catch for SQL Insert

      时间:2023-09-21

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

          <bdo id='hFUyb'></bdo><ul id='hFUyb'></ul>
          <tfoot id='hFUyb'></tfoot>
            1. <i id='hFUyb'><tr id='hFUyb'><dt id='hFUyb'><q id='hFUyb'><span id='hFUyb'><b id='hFUyb'><form id='hFUyb'><ins id='hFUyb'></ins><ul id='hFUyb'></ul><sub id='hFUyb'></sub></form><legend id='hFUyb'></legend><bdo id='hFUyb'><pre id='hFUyb'><center id='hFUyb'></center></pre></bdo></b><th id='hFUyb'></th></span></q></dt></tr></i><div id='hFUyb'><tfoot id='hFUyb'></tfoot><dl id='hFUyb'><fieldset id='hFUyb'></fieldset></dl></div>
              <legend id='hFUyb'><style id='hFUyb'><dir id='hFUyb'><q id='hFUyb'></q></dir></style></legend>
                  <tbody id='hFUyb'></tbody>
                本文介绍了PHP Try and Catch for SQL Insert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我的网站上有一个页面(高流量),每次加载页面时都会插入.

                I have a page on my website (high traffic) that does an insert on every page load.

                我很好奇最快和最安全的方法(捕获错误)并在系统无法插入 MySQL 时继续.我应该使用 try/catch 或 die 还是其他什么.我想确保插入发生,但如果由于某种原因它不能,我希望页面仍然继续加载.

                I am curious of the fastest and safest way to (catch an error) and continue if the system is not able to do the insert into MySQL. Should I use try/catch or die or something else. I want to make sure the insert happens but if for some reason it can't I want the page to continue to load anyway.

                ...
                $db = mysql_select_db('mobile', $conn);
                mysql_query("INSERT INTO redirects SET ua_string = '$ua_string'") or die('Error #10');
                mysql_close($conn);
                ...
                

                推荐答案

                检查 文档 表明其出错时返回 false.所以使用返回状态而不是 或 die().如果失败,它将返回 false,您可以记录(或任何您想做的事情)然后继续.

                Checking the documentation shows that its returns false on an error. So use the return status rather than or die(). It will return false if it fails, which you can log (or whatever you want to do) and then continue.

                $rv = mysql_query("INSERT INTO redirects SET ua_string = '$ua_string'");
                if ( $rv === false ){
                     //handle the error here
                }
                //page continues loading
                

                这篇关于PHP Try and Catch for SQL Insert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:PHP 在验证错误后保留输入的值 下一篇:在插入之前检查预先存在的记录的最快方法 [my

                相关文章

                最新文章

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

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