久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='6X3mz'><style id='6X3mz'><dir id='6X3mz'><q id='6X3mz'></q></dir></style></legend>

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

    <small id='6X3mz'></small><noframes id='6X3mz'>

    1. 使用 PDO 轉義列名

      escaping column name with PDO(使用 PDO 轉義列名)
        <tbody id='af4A1'></tbody>

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

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

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

              1. <legend id='af4A1'><style id='af4A1'><dir id='af4A1'><q id='af4A1'></q></dir></style></legend>
              2. 本文介紹了使用 PDO 轉義列名的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個類似的功能

                function getInfoById($id, $info) {
                
                }
                

                這個想法是有一個查詢 "SELECT $info FROM table WHERE id = $id"

                the idea is to have a query be "SELECT $info FROM table WHERE id = $id"

                這不適用于 PDO,因為您無法對列名進行轉義.我也真的不想使用 "SELECT *" 因為這不會返回更大的結果集并使用更多內存嗎?

                This doesn't work with PDO because you can't escape column names. I also don't really want to use "SELECT *" because doesn't that return a bigger result set and use more memory?

                推薦答案

                是的,PDO 沒有用于分隔標識符(如表名和列名)的內置函數.PDO::quote() 函數僅適用于字符串文字和日期文字.

                Yes, PDO does not have a builtin function for delimiting identifiers like table names and column names. The PDO::quote() function is only for string literals and date literals.

                無論如何,當我在 Zend Framework 上工作時,我實現了一個 quoteIdentifier() 函數.

                For what it's worth, when I worked on Zend Framework, I implemented a quoteIdentifier() function.

                SELECT * 獲取所有列是對的,這可能會使用更多內存并破壞覆蓋索引的好處.

                You're right that SELECT * fetches all columns, likely using more memory and spoiling the benefit of covering indexes.

                我的建議是將列名稱列入白名單.也就是說,確保 $info 實際上命名了 table 的一列.然后您無需擔心列名稱不存在,或包含奇怪字符或任何內容.您可以控制可以合法放入查詢中的列集.

                My recommendation is to whitelist column names. That is, make sure $info actually names a column of table. Then you don't need to worry about the column name not existing, or containing a strange character, or anything. You get to control the set of columns that are legitimate to put in the query.

                無論如何,您還應該分隔列名稱.如果列名稱包含標點符號、空格、國際字符或匹配 SQL 保留字,則需要分隔標識符.請參閱不同的數據庫是否使用不同的名稱引用?

                You should also delimit the column name anyway. Delimited identifiers are necessary if the column name contains punctuation, whitespace, international characters, or matches an SQL reserved word. See Do different databases use different name quote?

                function getInfoById($id, $info) {
                    // you can make this a literal list, or query it from DESC or INFORMATION_SCHEMA
                    $cols = array('col1', 'col2', 'col3');
                
                    if (array_search($info, $cols) === false) {
                      return false;
                    }
                    $sql = "SELECT `$info` FROM table WHERE id = :id";
                    $stmt = $pdo->prepare($sql);
                    if ($stmt === false) {
                      return false;
                    }
                    . . .
                }
                

                我在演示文稿中展示了更多白名單示例 SQL 注入神話和謬論.

                I show more examples of whitelisting in my presentation SQL Injection Myths and Fallacies.

                這篇關于使用 PDO 轉義列名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)
                <i id='dFItw'><tr id='dFItw'><dt id='dFItw'><q id='dFItw'><span id='dFItw'><b id='dFItw'><form id='dFItw'><ins id='dFItw'></ins><ul id='dFItw'></ul><sub id='dFItw'></sub></form><legend id='dFItw'></legend><bdo id='dFItw'><pre id='dFItw'><center id='dFItw'></center></pre></bdo></b><th id='dFItw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dFItw'><tfoot id='dFItw'></tfoot><dl id='dFItw'><fieldset id='dFItw'></fieldset></dl></div>
                <tfoot id='dFItw'></tfoot>

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

                    • <bdo id='dFItw'></bdo><ul id='dFItw'></ul>
                          <tbody id='dFItw'></tbody>
                          <legend id='dFItw'><style id='dFItw'><dir id='dFItw'><q id='dFItw'></q></dir></style></legend>
                        • 主站蜘蛛池模板: 亚洲精品欧美一区二区三区 | 久久香蕉网 | 国产欧美精品一区二区色综合 | 99国内精品 | 中文字幕在线一 | 亚洲视频在线观看 | 国产精品视频在线播放 | 日韩一区精品 | 小h片免费观看久久久久 | 免费视频一区二区三区在线观看 | 国产免费一二三区 | 久久久久久久久久久成人 | 久久精品欧美一区二区三区麻豆 | 中文字幕国产 | 亚洲日本成人 | 天堂精品 | 九九久久国产精品 | 久久精品小视频 | 成人国产精品免费观看视频 | 亚洲一区视频在线 | 国产精品久久久久久久 | 成人三级在线播放 | 亚洲精品一区二区 | 欧美日产国产成人免费图片 | 亚洲综合在线一区 | 国产91在线 | 中日 | 国产成人免费视频网站高清观看视频 | 国产一区 | 91精品久久久久久久久中文字幕 | 91婷婷韩国欧美一区二区 | 亚洲日韩中文字幕一区 | 国产日韩欧美一区 | 国产精品一区二区av | 亚洲精品av在线 | 亚洲精品www久久久久久广东 | 中文字幕精品一区 | 五月激情综合 | 国产综合久久 | 美人の美乳で授乳プレイ | 91视频正在播放 | 日韩精品一区二区三区视频播放 |