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

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

      <legend id='vkW5N'><style id='vkW5N'><dir id='vkW5N'><q id='vkW5N'></q></dir></style></legend>

          <bdo id='vkW5N'></bdo><ul id='vkW5N'></ul>

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

      1. 在插入之前檢查預(yù)先存在的記錄的最快方法 [my

        Quickest way to check for pre-existing record before insert [mysql_errno()](在插入之前檢查預(yù)先存在的記錄的最快方法 [mysql_errno()])

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

        <legend id='KPrqc'><style id='KPrqc'><dir id='KPrqc'><q id='KPrqc'></q></dir></style></legend>

          • <bdo id='KPrqc'></bdo><ul id='KPrqc'></ul>
            • <tfoot id='KPrqc'></tfoot>

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

                  本文介紹了在插入之前檢查預(yù)先存在的記錄的最快方法 [mysql_errno()]的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我的問題將以電子郵件為例,但這適用于任何事情.

                  My question will use emails as an example, but this could apply to anything.

                  通常在注冊新用戶(包括插入他/她的電子郵件)之前,我會檢查他/她的電子郵件是否已存在于數(shù)據(jù)庫中,如下所示:

                  Normally before registering a new user (including inserting his/her email) I check if his/her email already exists in the DB something like this:

                  $result = mysql_query("SELECT * FROM Users WHERE email = '".mysql_real_escape_string($email)"';");
                  if(!$result)
                  {
                      die(mysql_error());
                  }
                  
                  if(mysql_num_rows($result) > 0)
                  {
                      die('<p>Email already in DB. <a....>Recover Email</a></p>');
                  }
                  else
                  {
                      //insert new user data into Users table
                  }
                  


                  既然我已經(jīng)將我的用戶表中的 email 字段限制為 UNIQUE,那么首先嘗試插入如果失敗會不會更快,檢查錯誤?像這樣:


                  Since I'd have constrained the email field in my Users table to be UNIQUE anyway, wouldn't it be quicker to try to insert first and if it fails, check the error? Something like this:

                  $result = mysql_query(...);//insert new user data into Users table
                  if(!$result)
                  {
                      if(mysql_errno()==$insert_unique_error)
                      {
                          $error = '<p>Email already in DB. <a....>Recover Email</a></p>';
                      }
                      else
                      {
                          $error = mysql_error();
                      }
                      die($die_str);
                  }
                  

                  問題是我不知道$insert_unique_error 應(yīng)該是什么.這些是我能找到的唯一錯誤代碼:

                  The problem is that I don't know what $insert_unique_error should be. These are the only error codes I could find:

                  SQLSTATE 值的前兩個字符表示錯誤類別:

                  The first two characters of an SQLSTATE value indicate the error class:

                  Class = '00' 表示成功.

                  Class = '00' indicates success.

                  Class = '01' 表示警告.

                  Class = '01' indicates a warning.

                  Class = '02' 表示未找到".這與游標(biāo)上下文相關(guān),用于控制游標(biāo)到達(dá)數(shù)據(jù)集末尾時發(fā)生的情況.對于不檢索任何行的 SELECT ... INTO var_list 語句,也會出現(xiàn)這種情況.

                  Class = '02' indicates "not found." This is relevant within the context of cursors and is used to control what happens when a cursor reaches the end of a data set. This condition also occurs for SELECT ... INTO var_list statements that retrieve no rows.

                  類 >02"表示異常.

                  Class > '02' indicates an exception.

                  推薦答案

                  使用

                  INSERT IGNORE INTO Users VALUES(...);
                  

                  在電子郵件字段上使用唯一鍵,然后使用 mysql_affected_rows() 來檢查行數(shù);

                  with a unique key on email field, then check row count with mysql_affected_rows();

                  這將導(dǎo)致對數(shù)據(jù)庫的單一查詢并排除 SELECT 和 INSERT 之間時間窗口的競爭條件

                  This will result in a single query to the DB and rule out the race condition of the time window between SELECT and INSERT

                  這篇關(guān)于在插入之前檢查預(yù)先存在的記錄的最快方法 [mysql_errno()]的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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準(zhǔn)備好的語句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的訪問被拒絕)
                1. <tfoot id='pChrI'></tfoot>
                  <i id='pChrI'><tr id='pChrI'><dt id='pChrI'><q id='pChrI'><span id='pChrI'><b id='pChrI'><form id='pChrI'><ins id='pChrI'></ins><ul id='pChrI'></ul><sub id='pChrI'></sub></form><legend id='pChrI'></legend><bdo id='pChrI'><pre id='pChrI'><center id='pChrI'></center></pre></bdo></b><th id='pChrI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pChrI'><tfoot id='pChrI'></tfoot><dl id='pChrI'><fieldset id='pChrI'></fieldset></dl></div>

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

                              <tbody id='pChrI'></tbody>

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

                          • 主站蜘蛛池模板: 久久精品无码一区二区三区 | 国产精品乱码一区二区三区 | 91热在线| 成人在线精品视频 | 天啪| 黄色毛片在线观看 | 久久精品一区 | 国外激情av | 婷婷在线免费 | 亚洲一区二区精品视频 | 欧美日韩一二区 | 波多野结衣在线观看一区二区三区 | 日韩av免费在线观看 | 一区二区国产精品 | 免费黄色片在线观看 | 国产亚洲高清视频 | 亚洲第一黄色网 | 亚洲精视频 | 国产日韩一区二区 | 日本久久精品视频 | 国产综合第一页 | 福利视频三区 | 超碰美女在线 | 91精品无人区卡一卡二卡三 | 日韩中文一区二区三区 | 91久久爽久久爽爽久久片 | 国产在线观看不卡一区二区三区 | 中文在线а√在线8 | 麻豆一区二区三区 | 91视视频在线观看入口直接观看 | 欧美一区二区三区精品免费 | 欧美日韩在线一区二区 | 亚洲在线一区 | 日韩中文字幕在线视频观看 | 中文字幕一级毛片 | 国产精品视频一二三区 | 一区二区三区免费 | 国产精品福利网站 | 婷婷国产一区 | 7777奇米影视| 成人精品视频在线 |