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

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

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

        <legend id='nRd2W'><style id='nRd2W'><dir id='nRd2W'><q id='nRd2W'></q></dir></style></legend>
      1. 將 PHP while 循環(huán)轉(zhuǎn)換為使用 PDO

        Convert PHP while loop to use PDO(將 PHP while 循環(huán)轉(zhuǎn)換為使用 PDO)

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

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

                <tfoot id='wZ4p5'></tfoot>
                1. 本文介紹了將 PHP while 循環(huán)轉(zhuǎn)換為使用 PDO的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我目前正在通過切換到 PDO 來更新我的應(yīng)用.我有以下代碼:

                  I'm currently updating my app by switching to PDO. I have the following code:

                  $stmt = $db->prepare("select * from `product` where productid in (:productidLst)");
                  $stmt->bindParam(":productidLst",$productidLst, PDO::PARAM_INT);
                  $stmt->execute();
                  

                  在上面的代碼之后,var $productidLst 是 1,2 我想使用 PDO 等價(jià)物:

                  The var $productidLst is 1,2 after the above code I would like to use the PDO equivalent of this:

                  while($rs=mysql_fetch_assoc($res)){
                      $rs['qty']=$_SESSION['basket'][$rs['productid']];
                      $rs['total'] += $rs['qty']*$rs['price'];
                      $total += $rs['total'];
                      $a[] = $rs;
                  }
                  

                  我嘗試了多種組合,但都沒有成功,因此將不勝感激(在第二個(gè)代碼塊中,$res 是 sql).其次,我已將參數(shù) $productidLst 設(shè)置為 INT 這是正確的還是應(yīng)該是字符串?

                  I have tried numerous combinations but not been successful so any help with this would be appreciated (in the 2nd code block $res was the sql). Secondly I have set the Parameter $productidLst to INT is this correct or should it be a string?

                  ------------更新 1---------------------------------------------------

                  --------------------UPDATE 1----------------------------------------------------

                  我嘗試了以下代碼:

                  $stmt = $db->prepare("select * from `product` where productid in (:productidLst)");
                  foreach ($stmt->execute(array(':productidLst' => $productidLst)) as $row) 
                  {
                      $total += $row['total'];
                  }
                  

                  返回:為 foreach() 錯(cuò)誤提供的無效參數(shù)

                  Which returns: Invalid argument supplied for foreach() error

                  推薦答案

                  PHP 手冊(cè)中的標(biāo)準(zhǔn)文檔通常很有幫助.PHP手冊(cè)中有一個(gè)用PDO執(zhí)行for循環(huán)的例子,PDO詳情.

                  The standard documentation in the PHP manual is usually pretty helpful. There is an example of executing a for loop with PDO in the PHP manual, PDO Details.

                  function getFruit($conn) {
                      $sql = 'SELECT name, color, calories FROM fruit ORDER BY name';
                      foreach ($conn->query($sql) as $row) {
                          print $row['name'] . "	";
                          print $row['color'] . "	";
                          print $row['calories'] . "
                  ";
                      }
                  }
                  

                  通過一些更改,該示例可以使用準(zhǔn)備好的語句.

                  With a few changes, the example can be made to use a prepared statement.

                  function getFruit($conn) {
                      $query = $conn->prepare('SELECT name, color, calories FROM fruit WHERE kind=:kind ORDER BY name');
                      $query->execute(array(':kind' => 'drupe'));
                      // alternatively you could use PDOStatement::fetchAll() and get rid of the loop
                      // this is dependent upon the design of your app
                      foreach ($query as $row) {
                          print $row['name'] . "	";
                          print $row['color'] . "	";
                          print $row['calories'] . "
                  ";
                      }
                  }
                  

                  您還可以使用 while 循環(huán)和 PDOStatement::fetch 獲取每一行.

                  You can also use a while loop and PDOStatement::fetch to get each row.

                  function getFruit($conn) {
                      $query = $conn->prepare('SELECT name, color, calories FROM fruit WHERE kind=:kind ORDER BY name');
                      $query->execute(array(':kind' => 'drupe'));
                      // alternatively you could use PDOStatement::fetchAll() and get rid of the loop
                      // this is dependent upon the design of your app
                      while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                          print $row['name'] . "	";
                          print $row['color'] . "	";
                          print $row['calories'] . "
                  ";
                      }
                  }
                  

                  PHP 手冊(cè)在提供創(chuàng)建后兩個(gè)版本所需的所有信息方面仍然非常有用.

                  The PHP manual remains quite helpful in providing all the necessary information to create the latter two versions.

                  上一個(gè)版本的解釋:假設(shè) $conn 是一個(gè)有效的 PDO 對(duì)象.$conn->prepare($sql) 返回一個(gè) PDOStatement 對(duì)象如果成功,false 失敗 OR 基于您的錯(cuò)誤處理的異常.因此,假設(shè)成功,我們希望實(shí)際從對(duì)象中獲取數(shù)據(jù).我們可以使用 $query->fetch() 在循環(huán)或 $query->fetchAll() 獲取依賴于您的應(yīng)用的數(shù)據(jù).傳入類常量 PDO::FETCH_ASSOC 將返回一個(gè)數(shù)據(jù)關(guān)聯(lián)數(shù)組.

                  Explanation of the last version: assuming $conn is a valid PDO object. $conn->prepare($sql) returns a PDOStatement object if successful, false on failure OR an exception based on your error handling. So, assuming success we would want to actually get the data from the object. We can use $query->fetch() in a loop or $query->fetchAll() to get the data dependent upon your app. Passing in the class constant PDO::FETCH_ASSOC will return, you guessed it, an associative array of data.

                  在功能上,foreachwhile 實(shí)現(xiàn)是等效的.從概念上講,foreach 更合適,因?yàn)?while 循環(huán)具有在靜態(tài)條件成立時(shí)循環(huán)的含義,而 foreach 循環(huán)遍歷 a 的元素收藏.閱讀一段時(shí)間之間的差異PHP 中的循環(huán)和 for 循環(huán)?" 部分故事.

                  Functionally, the foreach and while implementations are equivalent. Conceptually, a foreach is more appropriate, as a while loop has connotations of looping while a static condition holds, whereas foreach loops over elements of a collection. Read "Differences between a while loop and a for loop in PHP?" for part of the story.

                  請(qǐng)務(wù)必閱讀 關(guān)于 PDO 的 php.net 參考

                  這篇關(guān)于將 PHP while 循環(huán)轉(zhuǎn)換為使用 PDO的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                    <bdo id='ZXzKQ'></bdo><ul id='ZXzKQ'></ul>

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

                        • <legend id='ZXzKQ'><style id='ZXzKQ'><dir id='ZXzKQ'><q id='ZXzKQ'></q></dir></style></legend>

                            <tbody id='ZXzKQ'></tbody>
                          <tfoot id='ZXzKQ'></tfoot>

                            <i id='ZXzKQ'><tr id='ZXzKQ'><dt id='ZXzKQ'><q id='ZXzKQ'><span id='ZXzKQ'><b id='ZXzKQ'><form id='ZXzKQ'><ins id='ZXzKQ'></ins><ul id='ZXzKQ'></ul><sub id='ZXzKQ'></sub></form><legend id='ZXzKQ'></legend><bdo id='ZXzKQ'><pre id='ZXzKQ'><center id='ZXzKQ'></center></pre></bdo></b><th id='ZXzKQ'></th></span></q></dt></tr></i><div class="3qmin8m" id='ZXzKQ'><tfoot id='ZXzKQ'></tfoot><dl id='ZXzKQ'><fieldset id='ZXzKQ'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 等离子空气净化器_医用空气消毒机_空气净化消毒机_中央家用新风系统厂家_利安达官网 | 首页-恒温恒湿试验箱_恒温恒湿箱_高低温试验箱_高低温交变湿热试验箱_苏州正合 | 股票入门基础知识_股票知识_股票投资大师_格雷厄姆网 | 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 储能预警-储能消防系统-电池舱自动灭火装置-四川千页科技股份有限公司官网 | 杭州可当科技有限公司—流量卡_随身WiFi_AI摄像头一站式解决方案 | 喷涂流水线,涂装流水线,喷漆流水线-山东天意设备科技有限公司 | 蔡司三坐标-影像测量机-3D扫描仪-蔡司显微镜-扫描电镜-工业CT-ZEISS授权代理商三本工业测量 | 干法制粒机_智能干法制粒机_张家港市开创机械制造有限公司 | 空压机网_《压缩机》杂志| 石家庄律师_石家庄刑事辩护律师_石家庄取保候审-河北万垚律师事务所 | MVR蒸发器厂家-多效蒸发器-工业废水蒸发器厂家-康景辉集团官网 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 皮带机_移动皮带机_大倾角皮带机_皮带机厂家 - 新乡市国盛机械设备有限公司 | 深圳美安可自动化设备有限公司,喷码机,定制喷码机,二维码喷码机,深圳喷码机,纸箱喷码机,东莞喷码机 UV喷码机,日期喷码机,鸡蛋喷码机,管芯喷码机,管内壁喷码机,喷码机厂家 | 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | 医疗仪器模块 健康一体机 多参数监护仪 智慧医疗仪器方案定制 血氧监护 心电监护 -朗锐慧康 | 学校用栓剂模,玻璃瓶轧盖钳,小型安瓿熔封机,实验室安瓿熔封机-长沙中亚制药设备有限公司 | 减速机电机一体机_带电机减速器一套_德国BOSERL电动机与减速箱生产厂家 | 武汉刮刮奖_刮刮卡印刷厂_为企业提供门票印刷_武汉合格证印刷_现金劵代金券印刷制作 - 武汉泽雅印刷有限公司 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 沈阳建筑设计公司_加固改造设计_厂房设计_设计资质加盟【金辉设计】 | 锌合金压铸-铝合金压铸厂-压铸模具-冷挤压-誉格精密压铸 | 首页 - 军军小站|张军博客| 三佳互联一站式网站建设服务|网站开发|网站设计|网站搭建服务商 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 线材成型机,线材折弯机,线材成型机厂家,贝朗自动化设备有限公司1 | 皮带机_移动皮带机_大倾角皮带机_皮带机厂家 - 新乡市国盛机械设备有限公司 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 工程管道/塑料管材/pvc排水管/ppr给水管/pe双壁波纹管等品牌管材批发厂家-河南洁尔康建材 | 专业甜品培训学校_广东糖水培训_奶茶培训_特色小吃培训_广州烘趣甜品培训机构 | 加热制冷恒温循环器-加热制冷循环油浴-杭州庚雨仪器有限公司 | 探鸣起名网-品牌起名-英文商标起名-公司命名-企业取名包满意 | 皮带机-带式输送机价格-固定式胶带机生产厂家-河南坤威机械 | 企业VI设计_LOGO设计公司_品牌商标设计_【北京美研】 | 半自动预灌装机,卡式瓶灌装机,注射器灌装机,给药器灌装机,大输液灌装机,西林瓶灌装机-长沙一星制药机械有限公司 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 商秀—企业短视频代运营_抖音企业号托管 |