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. 主站蜘蛛池模板: 信阳市建筑勘察设计研究院有限公司 | 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | 塑料熔指仪-塑料熔融指数仪-熔体流动速率试验机-广东宏拓仪器科技有限公司 | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 北京租车公司_汽车/客车/班车/大巴车租赁_商务会议/展会用车/旅游大巴出租_北京桐顺创业租车公司 | 钢衬四氟管道_钢衬四氟直管_聚四氟乙烯衬里管件_聚四氟乙烯衬里管道-沧州汇霖管道科技有限公司 | 高中学习网-高考生信息学习必备平台 | 置顶式搅拌器-优莱博化学防爆冰箱-磁驱搅拌器-天津市布鲁克科技有限公司 | 菲希尔FISCHER测厚仪-铁素体检测仪-上海吉馨实业发展有限公司 | 安徽千住锡膏_安徽阿尔法锡膏锡条_安徽唯特偶锡膏_卡夫特胶水-芜湖荣亮电子科技有限公司 | PCB厂|线路板厂|深圳线路板厂|软硬结合板厂|电路板生产厂家|线路板|深圳电路板厂家|铝基板厂家|深联电路-专业生产PCB研发制造 | 石膏基自流平砂浆厂家-高强石膏基保温隔声自流平-轻质抹灰石膏粉砂浆批发-永康市汇利建设有限公司 | crm客户关系管理系统,销售管理系统,crm系统,在线crm,移动crm系统 - 爱客crm | 智慧钢琴-电钢琴-便携钢琴-数码钢琴-深圳市特伦斯乐器有限公司 | 洛阳永磁工业大吊扇研发生产-工厂通风降温解决方案提供商-中实洛阳环境科技有限公司 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 生物制药洁净车间-GMP车间净化工程-食品净化厂房-杭州波涛净化设备工程有限公司 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 代写标书-专业代做标书-商业计划书代写「深圳卓越创兴公司」 | 苏州注册公司_苏州代理记账_苏州工商注册_苏州代办公司-恒佳财税 | 北京网站建设-企业网站建设-建站公司-做网站-北京良言多米网络公司 | 超声波清洗机_细胞破碎仪_实验室超声仪器_恒温水浴-广东洁盟深那仪器 | 耐酸碱泵-自吸耐酸碱泵型号「品牌厂家」立式耐酸碱泵价格-昆山国宝过滤机有限公司首页 | 东莞精密模具加工,精密连接器模具零件,自動機零件,冶工具加工-益久精密 | 电梯乘运质量测试仪_电梯安全评估测试仪-武汉懿之刻 | hc22_hc22价格_hc22哈氏合金—东锜特殊钢| 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 生物风-销售载体,基因,质粒,ATCC细胞,ATCC菌株等,欢迎购买-百风生物 | 行吊_电动单梁起重机_双梁起重机_合肥起重机_厂家_合肥市神雕起重机械有限公司 | 潜水搅拌机-双曲面搅拌机-潜水推进器|奥伯尔环保 | 压力控制器,差压控制器,温度控制器,防爆压力控制器,防爆温度控制器,防爆差压控制器-常州天利智能控制股份有限公司 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | LNG鹤管_内浮盘价格,上装鹤管,装车撬厂家-连云港赛威特机械 | 护腰带生产厂家_磁石_医用_热压护腰_登山护膝_背姿矫正带_保健护具_医疗护具-衡水港盛 | 北京亦庄厂房出租_经开区产业园招商信息平台 | 水冷式工业冷水机组_风冷式工业冷水机_水冷螺杆冷冻机组-深圳市普威机械设备有限公司 | 烽火安全网_加密软件、神盾软件官网 | 丝印油墨_水性油墨_环保油墨油漆厂家_37国际化工 | 商用绞肉机-熟肉切片机-冻肉切丁机-猪肉开条机 - 广州市正盈机械设备有限公司 | 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | 气动调节阀,电动调节阀,自力式压力调节阀,切断阀「厂家」-浙江利沃夫自控阀门 |