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

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

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

      1. <small id='rp3DG'></small><noframes id='rp3DG'>

        為什么帶有 mysqli 的面向對象 PHP 比過程方法更好

        Why is object oriented PHP with mysqli better than the procedural approach?(為什么帶有 mysqli 的面向對象 PHP 比過程方法更好?)
          • <tfoot id='2mNN6'></tfoot>

              <small id='2mNN6'></small><noframes id='2mNN6'>

                <legend id='2mNN6'><style id='2mNN6'><dir id='2mNN6'><q id='2mNN6'></q></dir></style></legend>
                • <bdo id='2mNN6'></bdo><ul id='2mNN6'></ul>
                • <i id='2mNN6'><tr id='2mNN6'><dt id='2mNN6'><q id='2mNN6'><span id='2mNN6'><b id='2mNN6'><form id='2mNN6'><ins id='2mNN6'></ins><ul id='2mNN6'></ul><sub id='2mNN6'></sub></form><legend id='2mNN6'></legend><bdo id='2mNN6'><pre id='2mNN6'><center id='2mNN6'></center></pre></bdo></b><th id='2mNN6'></th></span></q></dt></tr></i><div class="u2ok6ye" id='2mNN6'><tfoot id='2mNN6'></tfoot><dl id='2mNN6'><fieldset id='2mNN6'></fieldset></dl></div>
                    <tbody id='2mNN6'></tbody>
                • 本文介紹了為什么帶有 mysqli 的面向對象 PHP 比過程方法更好?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  直到最近,我一直在對 mysql* 使用過程方法.現在我想轉向 mysqli 和面向對象的方法.許多在線資源和書籍都指出,即使在 PHP 的情況下,OOP 也比過程化要好.在瀏覽了一些在線教程后,我編寫了一個連接數據庫并選擇一個值的小程序.我想知道為什么面向對象的方法更好?另外,這是編寫 OO php 網頁的正確方法嗎?

                  I have been using the procedural approach with mysql* until recently. Now I want to shift to mysqli and object oriented approach. Many online resources and books state that OOP is better than procedural even in case of PHP. After going through some online tutorials, I have written a small program that connects to the database and selects a value. I want to know why the object oriented approach is better? Plus is this the right way to code an OO php web page?

                  面向對象的方法

                  $host = "localhost";
                  $username = "root";
                  $password = "";
                  $dbname = "compdb";
                  
                  @ $db = new mysqli($host, $username, $password, $dbname);
                  
                  if(mysqli_connect_errno())
                  {
                      die("Connection could not be established");
                  }
                  
                  $query = "SELECT company_id FROM company_basic_details WHERE company_name = 'ABC'";
                  $result = $db->query($query);
                  
                  $total_num_rows = $result->num_rows;
                  
                  echo "The Results Are : <br>";
                  
                  while($row = $result->fetch_array())
                  {
                      echo $row['company_id'];
                  }
                  ?>
                  

                  程序方法

                  <?php
                  
                  $host = "localhost";
                  $username = "root";
                  $password = "";
                  $dbname = "compdb";
                  
                  @ $db = mysqli_connect($host, $username, $password, $dbname);
                  
                  if(mysqli_connect_errno())
                  {
                      die("Connection could not be established");
                  }
                  
                  $query = "SELECT company_id FROM company_basic_details WHERE company_name = 'ABC'";
                  $result = mysqli_query($db, $query);
                  
                  $total_num_rows = mysqli_num_rows($result);
                  
                  echo "The Results Are : <br>";
                  
                  while($row = mysqli_fetch_array($result))
                  {
                      echo $row['company_id'];
                  }
                  ?>
                  

                  推薦答案

                  主要原因是PHP正在向OO編程的方向穩步前進.

                  The main reason is that PHP is moving steadily in the direction of OO programming.

                  使用 mysqli_xxx() 函數而不是 OOP 等價函數沒有任何問題;就代碼而言,完全一樣.

                  There's nothing wrong with using mysqli_xxx() functions rather than the OOP equivalents; it is exactly the same as far as the code is concerned.

                  唯一的問題是,就人們認為編寫良好的 PHP 代碼而言,您將越來越落后于曲線.

                  The only issue is that you'll be getting yourself further and further behind the curve in terms of what people think of as well-written PHP code.

                  值得注意的是,被認為是 PHP 中大多數 DB 代碼的理想選擇的 PDO 庫是僅面向對象的.它沒有程序界面.并且在最后幾個版本中添加到 PHP 的大多數其他新功能也沒有.如果您想充分利用 PHP,無論如何您都需要了解 OOP.

                  It's worth noting that the PDO library, which is considered the ideal for most DB code in PHP is OOP-only. It doesn't have a procedural interface. And nor do most of the other new features added to PHP in the last few versions. If you want to use PHP to its fullest, you need to know OOP anyway.

                  還有一點是為您的數據庫創建擴展類的能力——就像這樣:

                  There's also the point about the ability to create an extension class for your DB -- something like this:

                  class myDB extends mysqli {
                       .... your own stuff here to extend and improve the base mysqli class
                  }
                  

                  當然你可以用過程代碼來實現同樣的事情,但它不像 OOP 方式那么簡潔.當然,這僅在您確實想擴展該類時才有意義.

                  Of course you can achieve the same thing with procedural code, but it's not as neat as the OOP way. And of course that's only relevant if you actually want to extend the class.

                  然而,作為第一步,從 mysql_xxx() 移動到 mysqli_xxx() 是一個很好的開始.將整個方式轉移到使用 OOP 接口會更好,但只是切換到 mysqli 函數是一個好的開始.

                  However, as a first step, just moving from mysql_xxx() to mysqli_xxx() is a great start. Moving the whole way to using the OOP interface would be even better, but just switching to the mysqli functions is a good start.

                  首先使用過程接口肯定會使從舊的 mysql_xx() 函數的過渡變得更容易,所以如果一開始切換到 OOP 接口是一個太大的飛躍,請不要不覺得你必須一口氣做完.從轉換為過程 mysqli 函數開始,然后稍后切換到 OOP 方法;這兩個跳躍本身都不會那么大.

                  Using the procedural interface to begin with will certainly make the transition away from the old mysql_xx() functions easier, so if switching to the OOP interface is too much of a leap at the beginning, don't feel you have to do it all in one go. Start with a conversion to the procedural mysqli functions, then switch to the OOP methods later on; neither jump will be that big on its own.

                  這篇關于為什么帶有 mysqli 的面向對象 PHP 比過程方法更好?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 中保持其類型?)
                    1. <i id='GS8iy'><tr id='GS8iy'><dt id='GS8iy'><q id='GS8iy'><span id='GS8iy'><b id='GS8iy'><form id='GS8iy'><ins id='GS8iy'></ins><ul id='GS8iy'></ul><sub id='GS8iy'></sub></form><legend id='GS8iy'></legend><bdo id='GS8iy'><pre id='GS8iy'><center id='GS8iy'></center></pre></bdo></b><th id='GS8iy'></th></span></q></dt></tr></i><div class="euegu4e" id='GS8iy'><tfoot id='GS8iy'></tfoot><dl id='GS8iy'><fieldset id='GS8iy'></fieldset></dl></div>

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

                          <legend id='GS8iy'><style id='GS8iy'><dir id='GS8iy'><q id='GS8iy'></q></dir></style></legend>
                        • <tfoot id='GS8iy'></tfoot>

                            <tbody id='GS8iy'></tbody>

                            <bdo id='GS8iy'></bdo><ul id='GS8iy'></ul>
                            主站蜘蛛池模板: 活动策划,舞台搭建,活动策划公司-首选美湖上海活动策划公司 | 云阳人才网_云阳招聘网_云阳人才市场_云阳人事人才网_云阳人家招聘网_云阳最新招聘信息 | 英超直播_英超免费在线高清直播_英超视频在线观看无插件-24直播网 | 内六角扳手「厂家」-温州市威豪五金工具有限公司 | 釜溪印象网络 - Powered by Discuz! | 流量卡中心-流量卡套餐查询系统_移动电信联通流量卡套餐大全 | 流变仪-热分析联用仪-热膨胀仪厂家-耐驰科学仪器商贸 | 冷油器-冷油器换管改造-连云港灵动列管式冷油器生产厂家 | 房在线-免费房产管理系统软件-二手房中介房屋房源管理系统软件 | 成人纸尿裤,成人尿不湿,成人护理垫-山东康舜日用品有限公司 | 余姚生活网_余姚论坛_余姚市综合门户网站| RTO换向阀_VOC高温阀门_加热炉切断阀_双偏心软密封蝶阀_煤气蝶阀_提升阀-湖北霍科德阀门有限公司 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | 嘉兴恒升声级计-湖南衡仪声级计-杭州爱华多功能声级计-上海邦沃仪器设备有限公司 | 炉门刀边腹板,焦化设备配件,焦化焦炉设备_沧州瑞创机械制造有限公司 | 深圳品牌设计公司-LOGO设计公司-VI设计公司-未壳创意 | 客服外包专业服务商_客服外包中心_网萌科技| 上海物流公司,上海货运公司,上海物流专线-优骐物流公司 | 混合生育酚_醋酸生育酚粉_琥珀酸生育酚-山东新元素生物科技 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 网架支座@球铰支座@钢结构支座@成品支座厂家@万向滑动支座_桥兴工程橡胶有限公司 | 上海诺狮景观规划设计有限公司| 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 废气处理_废气处理设备_工业废气处理_江苏龙泰环保设备制造有限公司 | 冻干机(冷冻干燥机)_小型|实验型|食品真空冷冻干燥机-松源 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | EFM 022静电场测试仪-套帽式风量计-静电平板监测器-上海民仪电子有限公司 | 顶空进样器-吹扫捕集仪-热脱附仪-二次热解吸仪-北京华盛谱信仪器 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 馋嘴餐饮网_餐饮加盟店火爆好项目_餐饮连锁品牌加盟指南创业平台 | 小学教案模板_中学教师优秀教案_高中教学设计模板_教育巴巴 | H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | 纳米涂料品牌 防雾抗污纳米陶瓷涂料厂家_虹瓷科技 | 百度爱采购运营研究社社群-店铺托管-爱采购代运营-良言多米网络公司 | PSI渗透压仪,TPS酸度计,美国CHAI PCR仪,渗透压仪厂家_价格,微生物快速检测仪-华泰和合(北京)商贸有限公司 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 黑龙江「京科脑康」医院-哈尔滨失眠医院_哈尔滨治疗抑郁症医院_哈尔滨精神心理医院 |