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

  • <small id='8I2T4'></small><noframes id='8I2T4'>

  • <legend id='8I2T4'><style id='8I2T4'><dir id='8I2T4'><q id='8I2T4'></q></dir></style></legend>

      <bdo id='8I2T4'></bdo><ul id='8I2T4'></ul>
    <tfoot id='8I2T4'></tfoot>

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

        如何從準備好的語句中獲取 assoc 數組中的所有內

        How to fetch all in assoc array from a prepared statement?(如何從準備好的語句中獲取 assoc 數組中的所有內容?)
          <tbody id='ytmVC'></tbody>

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

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

                • <bdo id='ytmVC'></bdo><ul id='ytmVC'></ul>
                  本文介紹了如何從準備好的語句中獲取 assoc 數組中的所有內容?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試此代碼:

                   if ($result = $this->mysqli->prepare("SELECT * FROM `mytable` WHERE `rows1`=?")){$result->bind_param("i",$id);$result->execute();while ($data = $result->fetch_assoc()){$statistic[] = $data;}echo "

                  ";var_dump($statistic);echo "</pre>";}

                  但它拋出以下錯誤

                  <塊引用>

                  [Fri Jun 15 12:13:11 2012] [error] [client 127.0.0.1] PHP 致命錯誤:調用 [myfile.php]

                  中未定義的方法 mysqli_stmt::fetch_assoc()

                  我也試過了:

                  if ($result = $this->mysqli->prepare("SELECT * FROM `mytable` WHERE `rows1`=?")){$result->bind_param("i",$id);$rows = $result->execute();while ($data = $rows->fetch_assoc()){$statistic[] = $data;}echo "

                  ";var_dump($statistic);echo "</pre>";}

                  就是這樣:

                  <塊引用>

                  [Fri Jun 15 12:22:59 2012] [error] [client 127.0.0.1] PHP 致命錯誤:在非對象上調用成員函數 fetch_assoc()[myfile.php]

                  我還能做什么來獲得結果或我做錯了什么?我需要來自 DB 的 assoc 數組,看起來像 $data[0]["id"] = 1

                  解決方案

                  事實上,您可以很容易地做到這一點,只是使用 mysqli_stmt 對象,你必須提取底層的mysqli_result,你可以通過簡單地調用 mysqli_stmt::get_result().注意:這需要 mysqlnd(MySQL Native Driver)擴展,它可能并不總是可用.

                  然而,下面關于推薦 PDO 而不是 MySQLi 的觀點仍然成立,這是一個很好的例子:MySQLi 用戶空間 API 沒有意義.我花了幾年時間間歇性地使用 MySQLi 才發現上述機制.現在,我承認將語句和結果集概念分開確實有意義,但在那種情況下,為什么語句有一個 fetch() 方法?值得深思(如果您仍然對 MySQLi 和 PDO 猶豫不決的話).

                  為了完整起見,這里有一個代碼示例(大致)基于問題中的原始代碼:

                  //創建語句$查詢 = "選擇 *從`mytable`哪里`rows1` =?";$stmt = $this->mysqli->prepare($query);//綁定參數并執行$stmt->bind_param("i", $id);//提取結果集并循環行$result = $stmt->get_result();while ($data = $result->fetch_assoc()){$statistic[] = $data;}//證明它在工作echo "

                  ";var_dump($statistic);echo "</pre>";

                  I'm trying this code:

                      if ($result = $this->mysqli->prepare("SELECT * FROM `mytable` WHERE `rows1`=?"))
                      {
                  
                          $result->bind_param("i",$id);
                          $result->execute();
                          while ($data = $result->fetch_assoc())
                          {
                  
                              $statistic[] = $data;
                  
                          }
                  
                          echo "<pre>";
                          var_dump($statistic);
                          echo "</pre>";
                      }
                  

                  but it's throwing the following error

                  [Fri Jun 15 12:13:11 2012] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined method mysqli_stmt::fetch_assoc() in [myfile.php]

                  And also I've tried:

                  if ($result = $this->mysqli->prepare("SELECT * FROM `mytable` WHERE `rows1`=?"))
                      {
                  
                          $result->bind_param("i",$id);
                          $rows = $result->execute();
                          while ($data = $rows->fetch_assoc())
                          {
                  
                              $statistic[] = $data;
                  
                          }
                  
                          echo "<pre>";
                          var_dump($statistic);
                          echo "</pre>";
                      }
                  

                  that makes this:

                  [Fri Jun 15 12:22:59 2012] [error] [client 127.0.0.1] PHP Fatal error: Call to a member function fetch_assoc() on a non-object in [myfile.php]

                  What else I can do for getting result or what I doing wrong? I need the assoc array from DB looking like $data[0]["id"] = 1

                  解決方案

                  In fact you can do this quite easily, you just can't do it with the mysqli_stmt object, you have to extract the underlying mysqli_result, you can do this by simply calling mysqli_stmt::get_result(). Note: this requires the mysqlnd (MySQL Native Driver) extension which may not always be available.

                  However, the point below about recommending PDO over MySQLi still stands, and this is a prime example of why: the MySQLi userland API makes no sense. It has taken me several years of intermittently working with MySQLi for me to discover the mechanism outlined above. Now, I'll admit that separating the statement and result-set concepts does make sense, but in that case why does a statement have a fetch() method? Food for thought (if you're still sitting on the fence between MySQLi and PDO).

                  For completeness, here's a code sample based (loosely) on the original code in the question:

                  // Create a statement
                  $query = "
                      SELECT *
                      FROM `mytable`
                      WHERE `rows1` = ?
                  ";
                  $stmt = $this->mysqli->prepare($query);
                  
                  // Bind params and execute
                  $stmt->bind_param("i", $id);
                  
                  // Extract result set and loop rows
                  $result = $stmt->get_result();
                  while ($data = $result->fetch_assoc())
                  {
                      $statistic[] = $data;
                  }
                  
                  // Proof that it's working
                  echo "<pre>";
                  var_dump($statistic);
                  echo "</pre>";
                  

                  這篇關于如何從準備好的語句中獲取 assoc 數組中的所有內容?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 中保持其類型?)

                          <tfoot id='nAT7X'></tfoot>
                        • <small id='nAT7X'></small><noframes id='nAT7X'>

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

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

                              <tbody id='nAT7X'></tbody>
                            主站蜘蛛池模板: 低浓度恒温恒湿称量系统,强光光照培养箱-上海三腾仪器有限公司 | 上海阳光泵业制造有限公司 -【官方网站】 | 北京晚会活动策划|北京节目录制后期剪辑|北京演播厅出租租赁-北京龙视星光文化传媒有限公司 | 安全阀_弹簧式安全阀_美标安全阀_工业冷冻安全阀厂家-中国·阿司米阀门有限公司 | 全自动变压器变比组别测试仪-手持式直流电阻测试仪-上海来扬电气 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 检验科改造施工_DSA手术室净化_导管室装修_成都特殊科室建设厂家_医疗净化工程公司_四川华锐 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 桁架楼承板-钢筋桁架楼承板-江苏众力达钢筋楼承板厂 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | 丁基胶边来料加工,医用活塞边角料加工,异戊二烯橡胶边来料加工-河北盛唐橡胶制品有限公司 | 线材成型机,线材折弯机,线材成型机厂家,贝朗自动化设备有限公司1 | 阻垢剂-反渗透缓蚀阻垢剂厂家-山东鲁东环保科技有限公司 | 防爆电机生产厂家,YBK3电动机,YBX3系列防爆电机,YBX4节防爆电机--河南省南洋防爆电机有限公司 | 【中联邦】增稠剂_增稠粉_水性增稠剂_涂料增稠剂_工业增稠剂生产厂家 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 智慧农业|农业物联网|现代农业物联网-托普云农物联网官方网站 | 四川成人高考_四川成考报名网 | 莱州网络公司|莱州网站建设|莱州网站优化|莱州阿里巴巴-莱州唯佳网络科技有限公司 | 云南外加剂,云南速凝剂,云南外加剂代加工-普洱澜湄新材料科技有限公司 | PC构件-PC预制构件-构件设计-建筑预制构件-PC构件厂-锦萧新材料科技(浙江)股份有限公司 | 铝合金电阻-无源谐波滤波器-上海稳达电讯设备厂 | 细石混凝土泵_厂家_价格-烟台九达机械有限公司 | 冰雕-冰雪世界-大型冰雕展制作公司-赛北冰雕官网| 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 | 穿线管|波纹穿线管|包塑金属软管|蛇皮管?闵彬专注弱电工程? | 合肥地磅_合肥数控切割机_安徽地磅厂家_合肥世佳电工设备有限公司 | 中医中药治疗血小板减少-石家庄血液病肿瘤门诊部 | 福建自考_福建自学考试网| 全自动包衣机-无菌分装隔离器-浙江迦南科技股份有限公司 | 陶氏道康宁消泡剂_瓦克消泡剂_蓝星_海明斯德谦_广百进口消泡剂 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 云南成考网_云南成人高考报名网 粤丰硕水性环氧地坪漆-防静电自流平厂家-环保地坪涂料代理 | 校车_校车价格_19座幼儿园校车_幼儿园校车_大鼻子校车 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 全屋整木定制-橱柜,家具定制-四川峨眉山龙马木业有限公司 | 深圳昂为官网-气体分析仪,沼气分析仪,动态配气仪,气体传感器厂家 | 小型手持气象站-空气负氧离子监测站-多要素微气象传感器-山东天合环境科技有限公司 | 电动葫芦|手拉葫芦|环链电动葫芦|微型电动葫芦-北京市凌鹰起重机械有限公司 |