久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='JD9xy'></tfoot>

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

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

      1. <i id='JD9xy'><tr id='JD9xy'><dt id='JD9xy'><q id='JD9xy'><span id='JD9xy'><b id='JD9xy'><form id='JD9xy'><ins id='JD9xy'></ins><ul id='JD9xy'></ul><sub id='JD9xy'></sub></form><legend id='JD9xy'></legend><bdo id='JD9xy'><pre id='JD9xy'><center id='JD9xy'></center></pre></bdo></b><th id='JD9xy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JD9xy'><tfoot id='JD9xy'></tfoot><dl id='JD9xy'><fieldset id='JD9xy'></fieldset></dl></div>
      2. PDO 異常問題 - 如何捕捉它們

        PDO Exception Questions - How to Catch Them(PDO 異常問題 - 如何捕捉它們)

          1. <legend id='8flCc'><style id='8flCc'><dir id='8flCc'><q id='8flCc'></q></dir></style></legend>
            <i id='8flCc'><tr id='8flCc'><dt id='8flCc'><q id='8flCc'><span id='8flCc'><b id='8flCc'><form id='8flCc'><ins id='8flCc'></ins><ul id='8flCc'></ul><sub id='8flCc'></sub></form><legend id='8flCc'></legend><bdo id='8flCc'><pre id='8flCc'><center id='8flCc'></center></pre></bdo></b><th id='8flCc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8flCc'><tfoot id='8flCc'></tfoot><dl id='8flCc'><fieldset id='8flCc'></fieldset></dl></div>

                <tbody id='8flCc'></tbody>

            1. <small id='8flCc'></small><noframes id='8flCc'>

              <tfoot id='8flCc'></tfoot>
                • <bdo id='8flCc'></bdo><ul id='8flCc'></ul>
                  本文介紹了PDO 異常問題 - 如何捕捉它們的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在使用 PDO 為數(shù)據(jù)庫重寫網(wǎng)站界面.我曾經(jīng)使用過mysql擴展,但我從來沒有為錯誤處理而煩惱,而且我擁有的少數(shù)錯誤處理程序基本上都是復(fù)制粘貼的.

                  I'm using PDO to re-write a website interface for a database. I used to use the mysql extension, but I had never bothered with error handling, and the few error handlers I had were basically copy-paste.

                  現(xiàn)在我想正確地做這件事.但是,我在捕捉我想要的錯誤時遇到了問題(MySQL 中的重復(fù)條目"、空值"等錯誤).我的語句中有多少需要在 try 塊中?所有的東西都應(yīng)該在那里嗎?我正在使用 Include() 連接到我的數(shù)據(jù)庫(它有自己的錯誤處理),所以只有查詢執(zhí)行在此代碼中有錯誤.我不明白為什么它在執(zhí)行以下代碼時沒有捕獲錯誤:

                  Now I'd like to do this right. However, I'm having issues catching the errors how I'd like (errors like "Duplicate Entry", "Null Value" etc in MySQL). How much of my statement needs to be in the try block? Should all of it be in there? I'm using an Include() to connect to my DB (which has its own error handling), so it's only the query execution which has errors in this code. I can't figure out why it's not catching an error when executing the following code:

                  try {
                    $stmt = $db->prepare("INSERT INTO tbl_user (id, name, password, question, answer)    VALUES (NULL, :name, :password, :question, :answer)");
                    $stmt->bindValue(":name", $_POST['name']);
                    $stmt->bindValue(":password", $_POST['password']);
                    $stmt->bindValue(":question", $_POST['question']);
                    $stmt->bindValue(":answer", $_POST['answer']);
                    $stmt->execute();
                    echo "Successfully added the new user " . $_POST['name'];
                  } catch (PDOException $e) {
                    echo "The user could not be added.<br>".$e->getMessage();
                  }
                  

                  所以我的問題是:所有這些都必須在 try 塊中嗎?我可以將執(zhí)行放在 try 塊中嗎?它應(yīng)該捕獲錯誤 Duplicate value "John" in key "name",而是通過成功消息.(嘗試添加兩個John"用戶時).我檢查了 PHPMyAdmin;索引是唯一的并且確實按預(yù)期拋出錯誤,只是不使用此代碼.

                  So my questions: does ALL OF THAT have to be in the try block? Can I just put the execute in the try block? It should catch the error Duplicate value "John" in key "name", but instead goes through with the success message. (When trying to add two "John" users). I checked in PHPMyAdmin; the index is unique and does throw the error as expected, just not using this code.

                  推薦答案

                  您應(yīng)該查看文檔.但是如果你沒有找到任何東西,你可以添加另一個捕獲:

                  You should look at the documentation. But If you dont find anything, you can add another catch :

                  <?php
                  try {
                    $stmt = $db->prepare("INSERT INTO tbl_user (id, name, password, question, answer)    VALUES (NULL, :name, :password, :question, :answer)");
                    $stmt->bindValue(":name", $_POST['name']);
                    $stmt->bindValue(":password", $_POST['password']);
                    $stmt->bindValue(":question", $_POST['question']);
                    $stmt->bindValue(":answer", $_POST['answer']);
                    $stmt->execute();
                    echo "Successfully added the new user " . $_POST['name'];
                  } catch (PDOException $e) {
                    echo "DataBase Error: The user could not be added.<br>".$e->getMessage();
                  } catch (Exception $e) {
                    echo "General Error: The user could not be added.<br>".$e->getMessage();
                  }
                  ?>
                  

                  這必須有效,因為 PHP 插件的所有異常都繼承自 Exception 原生 PHP 類.(如果我記性好的話,從 5.0 開始).

                  This must work because all exceptions of PHP plugins herits from the Exception native PHP class. (Since 5.0 if my memory is well).

                  這篇關(guān)于PDO 異常問題 - 如何捕捉它們的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)
                    <tbody id='jnNlD'></tbody>

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

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

                            主站蜘蛛池模板: 麻豆精品一区二区三区在线观看 | 日韩av中文 | 国产精品国产精品国产专区不卡 | 亚洲一级二级三级 | 欧美中国少妇xxx性高请视频 | 天堂在线www | 亚洲欧洲一区 | 欧美一区二区大片 | 欧美一区二区三区久久精品 | 在线观看亚洲精品视频 | 欧美专区在线 | www精品| 精品免费在线 | 91亚洲精品久久久电影 | 午夜影视大全 | 国产精品视频一区二区三区不卡 | 欧美日韩成人网 | 91九色视频 | 欧美视频第三页 | 九九一级片 | 亚洲精品一区二区三区丝袜 | 日日噜噜噜夜夜爽爽狠狠视频, | 91久久| 久久久福利 | 俺去俺来也www色官网cms | 日韩在线精品视频 | 在线午夜| 国产精品国产三级国产aⅴ中文 | 91久久久久久久久久久 | 国产成人免费视频 | 黑色丝袜三级在线播放 | 久久亚洲二区 | 日本高清精品 | 色久电影 | 国产精品国产a级 | 九九热免费视频在线观看 | 亚洲成人二区 | 亚洲午夜在线 | 一级做a爰片性色毛片视频停止 | 亚洲精品一区二区三区在线观看 | 国产一区二区三区视频 |