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

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

      1. <tfoot id='e0XPi'></tfoot>
          <bdo id='e0XPi'></bdo><ul id='e0XPi'></ul>
      2. <i id='e0XPi'><tr id='e0XPi'><dt id='e0XPi'><q id='e0XPi'><span id='e0XPi'><b id='e0XPi'><form id='e0XPi'><ins id='e0XPi'></ins><ul id='e0XPi'></ul><sub id='e0XPi'></sub></form><legend id='e0XPi'></legend><bdo id='e0XPi'><pre id='e0XPi'><center id='e0XPi'></center></pre></bdo></b><th id='e0XPi'></th></span></q></dt></tr></i><div class="35xl77f" id='e0XPi'><tfoot id='e0XPi'></tfoot><dl id='e0XPi'><fieldset id='e0XPi'></fieldset></dl></div>

      3. <legend id='e0XPi'><style id='e0XPi'><dir id='e0XPi'><q id='e0XPi'></q></dir></style></legend>

      4. 使用 MySQLi 準備語句時無法獲取行數和獲取

        Cannot get the number of rows and fetch when using MySQLi prepared statement(使用 MySQLi 準備語句時無法獲取行數和獲取)
      5. <tfoot id='4Wf6E'></tfoot>

            <tbody id='4Wf6E'></tbody>

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

            • <small id='4Wf6E'></small><noframes id='4Wf6E'>

                  <bdo id='4Wf6E'></bdo><ul id='4Wf6E'></ul>
                  <legend id='4Wf6E'><style id='4Wf6E'><dir id='4Wf6E'><q id='4Wf6E'></q></dir></style></legend>
                  本文介紹了使用 MySQLi 準備語句時無法獲取行數和獲取的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想從數據庫中獲取行數,但是當我嘗試這樣做時,$g_check 變量將等于 0 并且我的代碼將回顯$sugg_title 消息位于 else 語句中.但是在數據庫中有 4 個插入的組,所以 num_rows 屬性應該返回 4.

                  I want to get the number of rows from the database, but when I try to do this the $g_check variable will be equal to 0 and my code will echo the $sugg_title message which is in the else statement. But in the database there are 4 inserted groups so the num_rows property should return 4.

                  $sql = "SELECT DISTINCT gp.logo, gp.name
                          FROM gmembers AS gm
                          LEFT JOIN groups AS gp ON gp.name = gm.gname
                          WHERE gp.creator != ? AND gm.mname != ? LIMIT 10";
                  $stmt = $conn->prepare($sql);
                  $stmt->bind_param('ss',$log_username,$log_username);
                  $stmt->execute();
                  $g_check = $stmt->num_rows;
                  if ($g_check > 0){
                    $result = $stmt->get_result();
                    while ($row = $result->fetch_assoc()) {
                      $agList .= '<a href="group.php?g='.$row["name"].'"><img class="group_margin" src="groups/'.$row["name"].'/'.$row["logo"].'" alt="'.$row["name"].'" title="'.$row["name"].'" width="70" height="70" /></a>';
                    }
                  }else{
                    $sugg_title = "You have no group suggestions at the moment. Click ";
                    $sugg_title .= '<a href="all_groups.php">here</a> to view all groups.';
                  }
                  

                  我將 strore_result()fetch() 函數放在 execute() 之后,但隨后我收到此錯誤消息:致命錯誤:未捕獲的錯誤:在布爾值上調用成員函數 fetch_assoc()"

                  I put the strore_result() and the fetch() functions after execute() but then I get this error message: "Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean"

                  推薦答案

                  如果要使用mysqli_stmt::$num_rows(即檢查prepared statement上的行數),你需要在執行準備好的語句后使用 $stmt->store_result() 才能檢查行數.這意味著在我們檢查返回了多少行之前將結果存儲到內存中.

                  If you want to use mysqli_stmt::$num_rows (that is, check the number of rows on the prepared statement), you need to use $stmt->store_result() after executing the prepared statement before being able to check the number of rows. That means that the result is stored into memory before we check how many rows was returned.

                  $stmt = $conn->prepare($sql);
                  $stmt->bind_param('ss',$log_username,$log_username);
                  $stmt->execute();
                  $stmt->store_result(); // Need to store the result into memory first
                  if ($stmt->num_rows) {
                      // ...
                  

                  然而,如果你想使用mysqli_result::$num_rows(在你從語句結果轉換的MySQLi-result上),你需要在執行$result = $stmt->get_result();,并使用$result->num_rows;,如下所示.

                  However, if you want to use mysqli_result::$num_rows (on the MySQLi-result you convert from the statement result), you need to do that after doing $result = $stmt->get_result();, and use $result->num_rows;, like shown below.

                  $stmt = $conn->prepare($sql);
                  $stmt->bind_param('ss',$log_username,$log_username);
                  $stmt->execute();
                  $result = $stmt->get_result();
                  if ($result->num_rows) {
                      while ($row = $result->fetch_assoc()) {
                      // ....
                  

                  最后,他們都應該做同樣的事情 - 提供原始準備好的查詢返回的行數.

                  In the end, they should both end up doing the same thing - provide a number of the rows returned by the original prepared query.

                  注意
                  請務必注意,您不能在同一語句中使用 store_result()get_result().這意味著在第一個示例中,您不能轉換為 mysqli-result 對象(通過使用 get_result(),它允許您使用標準的 fetch_assoc() 方法).由于 store_result() 將結果存儲到內存中,get_result() 無需轉換,反之亦然.

                  Note
                  It's important to note that you cannot use store_result() and get_result() on the same statement. Which means that in the first example, you can not convert to a mysqli-result object (by using get_result(), which allows you to use the standard fetch_assoc() method). As store_result() stores the result into memory, there are nothing for get_result() to convert, and vice-versa.

                  這意味著如果你使用store_result(),你需要通過statement-fetch,mysqli_stmt::fetch()來獲取,并通過綁定結果>mysqli_stmt::bind_result().如果您使用 get_result(),您應該檢查結果 MySQLi-result 對象上的行數(如第二個示例所示).

                  This means that if you use store_result(), you need to fetch through the statement-fetch, mysqli_stmt::fetch() and bind the results though mysqli_stmt::bind_result(). If you use get_result(), you should check the number of rows on the resulting MySQLi-result object (as shown in the second example).

                  因此,您應該構建您的代碼,以便您只需要使用其中之一.

                  You should therefor construct your code such that you only need to use one of them.

                  話雖如此,使用 affected_rows 就像評論中建議的那樣,并不是適合這項工作的工具 - 根據 mysqli_stmt::$affected_rows 上的手冊(同樣的事情適用于常規查詢,mysqli::$affected_rows):

                  That being said, using affected_rows like suggested in the comments, isn't the right tool for the job - as per the manual on mysqli_stmt::$affected_rows (same thing applies for a regular query, mysqli::$affected_rows):

                  返回受 INSERT、UPDATE 或 DELETE 查詢影響的行數.
                  此函數僅適用于更新表的查詢.為了從 SELECT 查詢中獲取行數,請改用 mysqli_stmt_num_rows().

                  Returns the number of rows affected by INSERT, UPDATE, or DELETE query.
                  This function only works with queries which update a table. In order to get the number of rows from a SELECT query, use mysqli_stmt_num_rows() instead.

                  • PHP.net mysqli_stmt::store_result()
                  • PHP.net mysqli_stmt::get_result()
                  • PHP.net mysqli_stmt::$num_rows
                  • 這篇關于使用 MySQLi 準備語句時無法獲取行數和獲取的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準備好的語句問題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                  PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                  How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)

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

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

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

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

                            主站蜘蛛池模板: 沧州友城管业有限公司-内外涂塑钢管-大口径螺旋钢管-涂塑螺旋管-保温钢管生产厂家 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | 上海质量认证办理中心| 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 工业PH计|工业ph酸度计|在线PH计价格-合肥卓尔仪器仪表有限公司 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 乙炔气体报警装置|固定式氯化氢检测仪|河南驰诚电气百科 | pos机办理,智能/扫码/二维码/微信支付宝pos机-北京万汇通宝商贸有限公司 | 耐高温电缆厂家-远洋高温电缆 | 合肥网络推广_合肥SEO网站优化-安徽沃龙First | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 老城街小面官网_正宗重庆小面加盟技术培训_特色面馆加盟|牛肉拉面|招商加盟代理费用多少钱 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | loft装修,上海嘉定酒店式公寓装修公司—曼城装饰 | 德国BOSCH电磁阀-德国HERION电磁阀-JOUCOMATIC电磁阀|乾拓百科 | 点胶机_点胶阀_自动点胶机_智能点胶机_喷胶机_点胶机厂家【欧力克斯】 | EPK超声波测厚仪,德国EPK测厚仪维修-上海树信仪器仪表有限公司 | 全自动过滤器_反冲洗过滤器_自清洗过滤器_量子除垢环_量子环除垢_量子除垢 - 安士睿(北京)过滤设备有限公司 | 展厅设计公司,展厅公司,展厅设计,展厅施工,展厅装修,企业展厅,展馆设计公司-深圳广州展厅设计公司 | HEYL硬度计量泵-荧光法在线溶解氧仪-净时测控技术(上海)有限公司 | 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 钢衬四氟管道_钢衬四氟直管_聚四氟乙烯衬里管件_聚四氟乙烯衬里管道-沧州汇霖管道科技有限公司 | 液压压力机,液压折弯机,液压剪板机,模锻液压机-鲁南新力机床有限公司 | 光谱仪_积分球_分布光度计_灯具检测生产厂家_杭州松朗光电【官网】 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 除甲醛公司-甲醛检测-广西雅居环境科技有限公司 | 鲸鱼视觉 -数字展厅多媒体互动展示制作公司 | 涡轮流量计_LWGY智能气体液体电池供电计量表-金湖凯铭仪表有限公司 | 搪玻璃冷凝器_厂家-越宏化工设备| 昆明挖掘机修理厂_挖掘机翻新再制造-昆明聚力工程机械维修有限公司 | 隧道烘箱_隧道烘箱生产厂家-上海冠顶专业生产烘道设备 | 数控车床-立式加工中心-多功能机床-小型车床-山东临沂金星机床有限公司 | 免费分销系统 — 分销商城系统_分销小程序开发 -【微商来】 | 联系我们老街华纳娱乐公司官网19989979996(客服) | 脉冲布袋除尘器_除尘布袋-泊头市净化除尘设备生产厂家 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 不锈钢钢格栅板_热浸锌钢格板_镀锌钢格栅板_钢格栅盖板-格美瑞 | 奥因-光触媒除甲醛公司-除甲醛加盟公司十大品牌 | 菲希尔FISCHER测厚仪-铁素体检测仪-上海吉馨实业发展有限公司 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 |