pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <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="rxxqiev" 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. 在插入之前檢查預先存在的記錄的最快方法 [my

        Quickest way to check for pre-existing record before insert [mysql_errno()](在插入之前檢查預先存在的記錄的最快方法 [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="puyooyc" id='KPrqc'><tfoot id='KPrqc'></tfoot><dl id='KPrqc'><fieldset id='KPrqc'></fieldset></dl></div>

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

                  問題描述

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

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

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

                  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
                  }
                  


                  既然我已經將我的用戶表中的 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 應該是什么.這些是我能找到的唯一錯誤代碼:

                  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' 表示未找到".這與游標上下文相關,用于控制游標到達數據集末尾時發生的情況.對于不檢索任何行的 SELECT ... INTO var_list 語句,也會出現這種情況.

                  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() 來檢查行數;

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

                  這將導致對數據庫的單一查詢并排除 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

                  這篇關于在插入之前檢查預先存在的記錄的最快方法 [mysql_errno()]的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

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

                          • 主站蜘蛛池模板: 曙光腾达官网-天津脚手架租赁-木板架出租-移动门式脚手架租赁「免费搭设」 | 蜂蜜瓶-玻璃瓶-玻璃瓶厂-玻璃瓶生产厂家-徐州贵邦玻璃制品有限公司 | 欧版反击式破碎机-欧版反击破-矿山石料破碎生产线-青州奥凯诺机械 | 断桥铝破碎机_发动机破碎机_杂铝破碎机厂家价格-皓星机械 | 共享雨伞_共享童车_共享轮椅_共享陪护床-共享产品的领先者_有伞科技 | 深圳标识制作公司-标识标牌厂家-深圳广告标识制作-玟璟广告-深圳市玟璟广告有限公司 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 阴离子_阳离子聚丙烯酰胺厂家_聚合氯化铝价格_水处理絮凝剂_巩义市江源净水材料有限公司 | 周口风机|周风风机|河南省周口通用风机厂| 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 | 华溶溶出仪-Memmert稳定箱-上海协烁仪器科技有限公司 | 耐火浇注料价格-高强高铝-刚玉碳化硅耐磨浇注料厂家【直销】 | 低压载波电能表-单相导轨式电能表-华邦电力科技股份有限公司-智能物联网综合管理平台 | 彭世修脚_修脚加盟_彭世修脚加盟_彭世足疗加盟_足疗加盟连锁_彭世修脚技术培训_彭世足疗 | NMRV减速机|铝合金减速机|蜗轮蜗杆减速机|NMRV减速机厂家-东莞市台机减速机有限公司 | 东莞市天进机械有限公司-钉箱机-粘箱机-糊箱机-打钉机认准东莞天进机械-厂家直供更放心! | 磁棒电感生产厂家-电感器厂家-电感定制-贴片功率电感供应商-棒形电感生产厂家-苏州谷景电子有限公司 | 恒湿机_除湿加湿一体机_恒湿净化消毒一体机厂家-杭州英腾电器有限公司 | 玉米深加工设备-玉米深加工机械-新型玉米工机械生产厂家-河南粮院机械制造有限公司 | 苏州教学设备-化工教学设备-环境工程教学模型|同科教仪 | 上海阳光泵业制造有限公司 -【官方网站】| 科普仪器菏泽市教育教学仪器总厂| 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 档案密集柜_手动密集柜_智能密集柜_内蒙古档案密集柜-盛隆柜业内蒙古密集柜直销中心 | 地埋式垃圾站厂家【佳星环保】小区压缩垃圾中转站转运站 | 包塑软管|金属软管|包塑金属软管-闵彬管业 | 杭州门窗厂家_阳光房_包阳台安装电话-杭州窗猫铝合金门窗 | 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 优秀的临床医学知识库,临床知识库,医疗知识库,满足电子病历四级要求,免费试用 | 防堵吹扫装置-防堵风压测量装置-电动操作显示器-兴洲仪器 | 反渗透水处理设备|工业零排放|水厂设备|软化水设备|海南净水设备--海南水处理设备厂家 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 马尔表面粗糙度仪-MAHR-T500Hommel-Mitutoyo粗糙度仪-笃挚仪器 | 全国国际化学校_国际高中招生_一站式升学择校服务-国际学校网 | 碳钢法兰厂家,非标法兰,定制异型,法兰生产厂家-河北九瑞管道 | 超声骨密度仪-动脉硬化检测仪器-人体成分分析仪厂家/品牌/价格_南京科力悦 | 不锈钢酒柜|恒温酒柜|酒柜定制|酒窖定制-上海啸瑞实业有限公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 质检报告_CE认证_FCC认证_SRRC认证_PSE认证_第三方检测机构-深圳市环测威检测技术有限公司 | 机房监控|动环监控|动力环境监控系统方案产品定制厂家 - 迈世OMARA |