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

    <bdo id='VSNDQ'></bdo><ul id='VSNDQ'></ul>
  • <small id='VSNDQ'></small><noframes id='VSNDQ'>

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

      2. 為什么 PDO 比 mysql_real_escape_string 更適合轉義 My

        Why is PDO better for escaping MySQL queries/querystrings than mysql_real_escape_string?(為什么 PDO 比 mysql_real_escape_string 更適合轉義 MySQL 查詢/查詢字符串?)

      3. <legend id='qBMbx'><style id='qBMbx'><dir id='qBMbx'><q id='qBMbx'></q></dir></style></legend>
            <bdo id='qBMbx'></bdo><ul id='qBMbx'></ul>

          • <small id='qBMbx'></small><noframes id='qBMbx'>

                <tbody id='qBMbx'></tbody>

                • <tfoot id='qBMbx'></tfoot>
                  <i id='qBMbx'><tr id='qBMbx'><dt id='qBMbx'><q id='qBMbx'><span id='qBMbx'><b id='qBMbx'><form id='qBMbx'><ins id='qBMbx'></ins><ul id='qBMbx'></ul><sub id='qBMbx'></sub></form><legend id='qBMbx'></legend><bdo id='qBMbx'><pre id='qBMbx'><center id='qBMbx'></center></pre></bdo></b><th id='qBMbx'></th></span></q></dt></tr></i><div class="goo2qus" id='qBMbx'><tfoot id='qBMbx'></tfoot><dl id='qBMbx'><fieldset id='qBMbx'></fieldset></dl></div>
                • 本文介紹了為什么 PDO 比 mysql_real_escape_string 更適合轉義 MySQL 查詢/查詢字符串?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  有人告訴我,我最好使用 PDO 進行 MySQL 轉義,而不是 mysql_real_escape_string.

                  I've been told that I'd be better using PDO for MySQL escaping, rather than mysql_real_escape_string.

                  也許我正在度過一個腦殘的一天(或者可能是因為我絕對不是一個天生的程序員,而且我在 PHP 方面仍然處于新手階段),但是已經查看了 PHP 手冊并閱讀了 有關 PDO 的條目,我仍然不清楚 PDO 究竟是什么以及為什么它比使用 mysql_real_escape_string 更好.這可能是因為我還沒有真正掌握 OOP 的復雜性(我假設它與 OOP 有關),但除了變量和數組值似乎在它們前面有一個冒號這一事實之外,我仍然不確定它到底是什么以及你如何使用它(以及為什么它比 mysql_real_escape_string 更好.(這也可能與我并沒有真正清楚的事實有關)理解什么是類",所以當我讀到PDO 類"時,我真的一點也不聰明).

                  Maybe I'm having a brain-dead day (or it may be the fact I'm by no stretch of the imagination a natural programmer, and I'm still very much at the newbie stage when it comes to PHP), but having checked out the PHP manual and read the entry on PDO, I'm still no clearer as to what PDO actually is and why it's better than using mysql_real_escape_string. This may be because I've not really got to grips with the complexities of OOP yet (I'm assuming it's something to do with OOP), but other than the fact that variables and array values seem to have a colon infront of them, I'm still not sure what it actually is and how you use it (and why it's better than mysql_real_escape_string. (It also may have something to do with the fact that I don't really have a clear understanding of what 'classes' are, so when I read "PDO class" I'm none the wiser really).

                  已閱讀關于開發人員"的一兩篇文章MySQL網站的Zone'位,我仍然不清楚.由于目前我什至無法弄清楚它是什么,我認為現在使用它可能有點超出我的范圍,但我仍然有興趣擴大我的教育范圍并找出我可以改進的方法.

                  Having read an article or two on the 'Developer Zone' bit of the MySQL website, I'm still no clearer. As I can't even figure out what it is at the moment, I think probably using it is a bit beyond me right now, but I'm still interested in broadening my education and finding out how I could improve things.

                  誰能用簡單的英語"向我解釋什么是 PDO(或為我指明用簡單英語編寫的主題方向),以及您將如何使用它?

                  Could anyone explain to me in 'plain English' what PDO is (or point me in the direction of something on the subject written in plain English), and how you'd go about using it?

                  推薦答案

                  由于當前的答案進入了詳細信息,而您的問題更側重于總體概述,我會嘗試一下:

                  As the current answers go into details while your question is more aimed at a general overview, I'll give it a try:

                  PDO 類旨在封裝與數據庫交互所需的所有功能.他們通過定義方法"(函數的 OO 客廳)和屬性"(變量的 OO 客廳)來做到這一點.您可以將它們用作完全替代您現在用于與數據庫對話的所有標準"函數.

                  The PDO classes aim to encapsulate all the functionality needed to interact with a database. They do this by defining 'methods' (OO parlor for functions) and 'properties' (OO parlor for variables). You'd use them as a complete replacement for all the 'standard' functions you are using now for talking to a database.

                  因此,與其調用一系列 'mysql_doSomething()' 函數,將它們的結果存儲在您自己的變量中,您可以從 PDO 類中實例化"一個對象('class' = 抽象定義,'object' = 具體,類的可用實例)并調用該對象上的方法來執行相同的操作.

                  So instead of calling a series of the 'mysql_doSomething()' functions, storing their results in your own variables, you would 'instantiate' an object from the PDO class ('class' = abstract definition, 'object' = concrete, usable instance of a class) and call methods on that object to do the same.

                  舉個例子,如果沒有 PDO,你會做這樣的事情:

                  As an example, without PDO, you'd do something like this:

                  // Get a db connection
                  $connection = mysql_connect('someHost/someDB', 'userName', 'password');
                  // Prepare a query
                  $query = "SELECT * FROM someTable WHERE something = " . mysql_real_escape_string($comparison) . "'";
                  // Issue a query
                  $db_result = mysql_query($query);
                  // Fetch the results
                  $results = array();
                  while ($row = mysql_fetch_array($db_result)) {
                    $results[] = $row;
                  }
                  

                  雖然這與使用 PDO 是等效的:

                  while this would be the equivalent using PDO:

                  // Instantiate new PDO object (will create connection on the fly)
                  $db = new PDO('mysql:dbname=someDB;host=someHost');
                  // Prepare a query (will escape on the fly)
                  $statement = $db->prepare('SELECT * FROM someTable WHERE something = :comparison');
                  // $statement is now a PDOStatement object, with its own methods to use it, e.g.
                  // execute the query, passing in the parameters to replace
                  $statement->execute(array(':comparison' => $comparison));
                  // fetch results as array
                  $results = $statement->fetchAll();
                  

                  所以乍一看,除了語法之外,沒有太大區別.但是 PDO 版本有一些優點,最大的一個是數據庫獨立性:

                  So on first glance, there is not much difference, except in syntax. But the PDO version has some advantages, the biggest one being database independence:

                  如果您需要與 PostgreSQL 數據庫對話,您只需在實例化調用 new PDO()<中將 mysql: 更改為 pgsql:/代碼>.使用舊方法,您必須遍歷所有代碼,將所有 'mysql_doSomething()' 函數替換為其對應的 'pg_doSomthing()' 函數(始終檢查參數處理中的潛在差異).許多其他受支持的數據庫引擎也是如此.

                  If you need to talk to a PostgreSQL database instead, you'd only change mysql:to pgsql: in the instantiating call new PDO(). With the old method, you'd have to go through all your code, replacing all 'mysql_doSomething()' functions with their 'pg_doSomthing()' counterpart (always checking for potential differences in parameter handling). The same would be the case for many other supported database engines.

                  所以回到你的問題,PDO 基本上只是給你一種不同的方式來實現同樣的事情,同時提供一些捷徑/改進/優勢.例如,轉義會以您正在使用的數據庫引擎所需的正確方式自動發生.此外,參數替換(防止 SQL 注入,示例中未顯示)要容易得多,因此更不容易出錯.

                  So to get back to your question, PDO basically just gives you a different way to achieve the same things, while offering some shortcuts/improvements/advantages. For example, escaping would happen automatically in the proper way needed for the database engine you are using. Also parameter substitution (prevents SQL Injections, not shown in example) is much easier, making it less error prone.

                  您應該閱讀一些 OOP 基礎知識以了解其他優勢.

                  You should read up on some OOP basics to get an idea of other advantages.

                  這篇關于為什么 PDO 比 mysql_real_escape_string 更適合轉義 MySQL 查詢/查詢字符串?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

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

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

                          1. 主站蜘蛛池模板: 北京百度网站优化|北京网站建设公司-百谷网络科技 | 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | 手机游戏_热门软件app下载_好玩的安卓游戏下载基地-吾爱下载站 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 蓝米云-专注于高性价比香港/美国VPS云服务器及海外公益型免费虚拟主机 | 电脑知识|软件|系统|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网 | 水上浮桥-游艇码头-浮动码头-游船码头-码瑞纳游艇码头工程 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 水冷式工业冷水机组_风冷式工业冷水机_水冷螺杆冷冻机组-深圳市普威机械设备有限公司 | 对夹式止回阀厂家,温州对夹式止回阀制造商--永嘉县润丰阀门有限公司 | 深圳美安可自动化设备有限公司,喷码机,定制喷码机,二维码喷码机,深圳喷码机,纸箱喷码机,东莞喷码机 UV喷码机,日期喷码机,鸡蛋喷码机,管芯喷码机,管内壁喷码机,喷码机厂家 | 液晶拼接屏厂家_拼接屏品牌_拼接屏价格_监控大屏—北京维康 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 纸塑分离机-纸塑分离清洗机设备-压力筛-碎浆机厂家金双联环保 | 【德信自动化】点胶机_全自动点胶机_自动点胶机厂家_塑料热压机_自动螺丝机-深圳市德信自动化设备有限公司 | 网站建设-高端品牌网站设计制作一站式定制_杭州APP/微信小程序开发运营-鼎易科技 | 盘装氧量分析仪-防爆壁挂氧化锆分析仪-安徽吉帆仪表有限公司 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 扒渣机,铁水扒渣机,钢水扒渣机,铁水捞渣机,钢水捞渣机-烟台盛利达工程技术有限公司 | Win10系统下载_32位/64位系统/专业版/纯净版下载 | 有机废气处理-rto焚烧炉-催化燃烧设备-VOC冷凝回收装置-三梯环境 | 馋嘴餐饮网_餐饮加盟店火爆好项目_餐饮连锁品牌加盟指南创业平台 | 电气控制系统集成商-PLC控制柜变频控制柜-非标自动化定制-电气控制柜成套-NIDEC CT变频器-威肯自动化控制 | 垃圾压缩设备_垃圾处理设备_智能移动式垃圾压缩设备--山东明莱环保设备有限公司 | 无纺布包装机|径向缠绕包装机|缠绕膜打包机-上海晏陵智能设备有限公司 | 南京兰江泵业有限公司-水解酸化池潜水搅拌机-絮凝反应池搅拌机-好氧区潜水推进器 | 海德莱电力(HYDELEY)-无功补偿元器件生产厂家-二十年专业从事电力电容器 | 生物颗粒燃烧机-生物质燃烧机-热风炉-生物颗粒蒸汽发生器-丽水市久凯能源设备有限公司 | 北京翻译公司_同传翻译_字幕翻译_合同翻译_英语陪同翻译_影视翻译_翻译盖章-译铭信息 | 北京森语科技有限公司-模型制作专家-展览展示-沙盘模型设计制作-多媒体模型软硬件开发-三维地理信息交互沙盘 | 产业规划_产业园区规划-产业投资选址及规划招商托管一体化服务商-中机院产业园区规划网 | 上海冠顶工业设备有限公司-隧道炉,烘箱,UV固化机,涂装设备,高温炉,工业机器人生产厂家 | 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 耐驰泵阀管件制造-耐驰泵阀科技(天津)有限公司 | 博医通医疗器械互联网供应链服务平台_博医通 | 旅游规划_旅游策划_乡村旅游规划_景区规划设计_旅游规划设计公司-北京绿道联合旅游规划设计有限公司 | 广州展览制作|展台制作工厂|展览设计制作|展览展示制作|搭建制作公司 | 气力输送_输送机械_自动化配料系统_负压吸送_制造主力军江苏高达智能装备有限公司! | 天津中都白癜风医院_天津白癜风医院_天津治疗白癜风 | 分轨 | 上传文件,即刻分离人声和伴奏 |