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

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

    1. <legend id='B4JtN'><style id='B4JtN'><dir id='B4JtN'><q id='B4JtN'></q></dir></style></legend>

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

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

        嘗試訪問(wèn) bool 類型值的數(shù)組偏移量

        Trying to access array offset on value of type bool(嘗試訪問(wèn) bool 類型值的數(shù)組偏移量)
          <tbody id='KoSZL'></tbody>
          <bdo id='KoSZL'></bdo><ul id='KoSZL'></ul>
        • <legend id='KoSZL'><style id='KoSZL'><dir id='KoSZL'><q id='KoSZL'></q></dir></style></legend>

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

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

                  本文介紹了嘗試訪問(wèn) bool 類型值的數(shù)組偏移量的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  $query = $pdo -> prepare("SELECT * FROM Users WHERE Username =:Username");
                  $query->bindParam(':Username', $name);
                  $query->execute();
                  
                  $nameRes = $query->fetch(PDO::FETCH_ASSOC);
                  if ($nameRes['Username']==$_POST['username']) {
                      die ("Username is already in use!");
                  }   
                  
                  $query = $pdo -> prepare("SELECT * FROM Users WHERE Email =:Email");
                  $query->bindParam(':Email', $email);
                  $query ->execute();
                  $emailRes = $query->fetch(PDO::FETCH_ASSOC);
                  
                  if ($emailRes['Email']==$_POST['email']) {
                      die ("Email is already in use!");
                  }
                  

                  我在我的應(yīng)用程序的注冊(cè)頁(yè)面上有這個(gè)代碼,當(dāng)用戶名可以免費(fèi)使用但電子郵件不是,反之亦然我得到這個(gè)

                  I have this code on the registration page of my app and when Username is free to use but email is not and vice versa I get this

                  注意:嘗試訪問(wèn) bool 類型值的數(shù)組偏移量

                  Notice: Trying to access array offset on value of type bool

                  好的,結(jié)果返回false,但在這種情況下該怎么辦?注意:這是在 php v7.4 上,同樣的事情在 v7.3 上工作

                  Ok the result is returning false but what to do in this situation? Note: This is on php v7.4 this same thing was working on v7.3

                  推薦答案

                  您收到此錯(cuò)誤可能是因?yàn)樵跀?shù)據(jù)庫(kù)中找不到符合您條件的記錄.

                  解決此錯(cuò)誤的最簡(jiǎn)單方法是先檢查數(shù)據(jù)庫(kù)是否返回任何內(nèi)容.

                  The easiest way to solve this error is to check if the database returned anything first.

                  $emailRes = $query->fetch(PDO::FETCH_ASSOC);
                  // VVV - Here I am checking if there was anything returned and then I check the condition
                  if($emailRes && $emailRes['Email']==$_POST['email']) {
                      // ...
                  }
                  

                  如果您不在乎數(shù)據(jù)庫(kù)是否返回任何內(nèi)容,那么您可以簡(jiǎn)單地提供一個(gè)默認(rèn)值.例如:

                  If you don't care whether the database returned anything, then you can simply provide a default value. For example:

                  $emailRes = $query->fetch(PDO::FETCH_ASSOC);
                  $email = $emailRes['Email'] ?? ''; // default: empty string
                  

                  使用 PDO 檢查 DB 中是否存在的正確方法是:

                  The correct way to check for existance in DB using PDO is:

                  $query = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE Username =:Username");
                  $query->execute([':Username' => $name]);
                  if ($query->fetchColumn()) {
                      throw new Exception("Username is already in use!");
                  }
                  
                  $query = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE Email =:Email");
                  $query->execute([':Email' => $email]);
                  if ($query->fetchColumn()) {
                      throw new Exception("Email is already in use!");
                  }
                  

                  我沒(méi)有在 PHP 中獲取行并再次進(jìn)行比較,而是從數(shù)據(jù)庫(kù)中獲取匹配行的計(jì)數(shù),并將該計(jì)數(shù)用作 if 語(yǔ)句中的布爾值.fetchColumn() 將從第一行獲取單列,如果我使用 COUNT(*) 我知道總會(huì)有一行.

                  Instead of fetching the row and doing the comparison again in PHP I am fetching a count of matching rows from the database and I use that count as a boolean in the if statement. fetchColumn() will fetch a single column from the first row and if I use COUNT(*) I know there will always be one row.

                  您也可以在一個(gè)查詢中完成:

                  You can also do it in one query:

                  $query = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE Username =:Username OR  Email =:Email");
                  $query->execute([':Username' => $name, ':Email' => $email]);
                  if ($query->fetchColumn()) {
                      throw new Exception("Username or email is already in use!");
                  }
                  

                  這篇關(guān)于嘗試訪問(wèn) bool 類型值的數(shù)組偏移量的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語(yǔ)句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無(wú)法識(shí)別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(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的訪問(wèn)被拒絕)

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

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

                    <legend id='aH0Z5'><style id='aH0Z5'><dir id='aH0Z5'><q id='aH0Z5'></q></dir></style></legend>
                        <tbody id='aH0Z5'></tbody>

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

                          <i id='aH0Z5'><tr id='aH0Z5'><dt id='aH0Z5'><q id='aH0Z5'><span id='aH0Z5'><b id='aH0Z5'><form id='aH0Z5'><ins id='aH0Z5'></ins><ul id='aH0Z5'></ul><sub id='aH0Z5'></sub></form><legend id='aH0Z5'></legend><bdo id='aH0Z5'><pre id='aH0Z5'><center id='aH0Z5'></center></pre></bdo></b><th id='aH0Z5'></th></span></q></dt></tr></i><div class="fidnejw" id='aH0Z5'><tfoot id='aH0Z5'></tfoot><dl id='aH0Z5'><fieldset id='aH0Z5'></fieldset></dl></div>
                          • 主站蜘蛛池模板: 杭州顺源过滤机械有限公司官网-压滤机_板框压滤机_厢式隔膜压滤机厂家 | 无锡网站建设_企业网站定制-网站制作公司-阿凡达网络 | UV-1800紫外光度计-紫外可见光度计厂家-翱艺仪器(上海)有限公司 | 东莞画册设计_logo/vi设计_品牌包装设计 - 华略品牌设计公司 | 深圳昂为官网-气体分析仪,沼气分析仪,动态配气仪,气体传感器厂家 | 硬度计_影像测量仪_维氏硬度计_佛山市精测计量仪器设备有限公司厂家 | 隆众资讯-首页_大宗商品资讯_价格走势_市场行情 | 电脑知识|软件|系统|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网 | 南京技嘉环保科技有限公司-杀菌除臭剂|污水|垃圾|厕所|橡胶厂|化工厂|铸造厂除臭剂 | 岸电电源-60HZ变频电源-大功率变频电源-济南诚雅电子科技有限公司 | 分光色差仪,测色仪,反透射灯箱,爱色丽分光光度仪,美能达色差仪维修_苏州欣美和仪器有限公司 | Win10系统下载_32位/64位系统/专业版/纯净版下载 | 氧化铝球_高铝球_氧化铝研磨球-淄博誉洁陶瓷新材料有限公司 | 收录网| ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 苏州伊诺尔拆除公司_专业酒店厂房拆除_商场学校拆除_办公楼房屋拆除_家工装拆除拆旧 | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 砖机托板价格|免烧砖托板|空心砖托板厂家_山东宏升砖机托板厂 | 小型玉石雕刻机_家用玉雕机_小型万能雕刻机_凡刻雕刻机官网 | Type-c防水母座|贴片母座|耳机接口|Type-c插座-深圳市步步精科技有限公司 | 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 安徽合肥项目申报咨询公司_安徽合肥高新企业项目申报_安徽省科技项目申报代理 | 振动时效_振动时效仪_超声波冲击设备-济南驰奥机电设备有限公司 北京宣传片拍摄_产品宣传片拍摄_宣传片制作公司-现像传媒 | 模型公司_模型制作_沙盘模型报价-中国模型网 | CTAB,表面活性剂1631溴型(十六烷基三甲基溴化铵)-上海升纬化工原料有限公司 | 振动传感器,检波器-威海广达勘探仪器有限公司 | 电动不锈钢套筒阀-球面偏置气动钟阀-三通换向阀止回阀-永嘉鸿宇阀门有限公司 | 起好名字_取个好名字_好名网免费取好名在线打分 | PCB设计,PCB抄板,电路板打样,PCBA加工-深圳市宏力捷电子有限公司 | 智能化的检漏仪_气密性测试仪_流量测试仪_流阻阻力测试仪_呼吸管快速检漏仪_连接器防水测试仪_车载镜头测试仪_奥图自动化科技 | ge超声波测厚仪-电动涂膜机-电动划格仪-上海洪富| 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 沈阳液压泵_沈阳液压阀_沈阳液压站-沈阳海德太科液压设备有限公司 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 定量包装秤,吨袋包装称,伸缩溜管,全自动包装秤,码垛机器人,无锡市邦尧机械工程有限公司 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 | 伶俐嫂培训学校_月嫂培训班在哪里报名学费是多少_月嫂免费政府培训中心推荐 | 浙江浩盛阀门有限公司|