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

    • <bdo id='0QtOb'></bdo><ul id='0QtOb'></ul>

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

      <small id='0QtOb'></small><noframes id='0QtOb'>

        <legend id='0QtOb'><style id='0QtOb'><dir id='0QtOb'><q id='0QtOb'></q></dir></style></legend>

        如何使用 PDO 動態構建查詢

        How to dynamically build queries with PDO(如何使用 PDO 動態構建查詢)
          <tbody id='tcEaz'></tbody>
        <legend id='tcEaz'><style id='tcEaz'><dir id='tcEaz'><q id='tcEaz'></q></dir></style></legend>

            <tfoot id='tcEaz'></tfoot>
              <bdo id='tcEaz'></bdo><ul id='tcEaz'></ul>

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

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

                  本文介紹了如何使用 PDO 動態構建查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 PDO 并且想做這樣的事情:

                  $query = $dbh->prepare("SELECT * FROM :table WHERE :column = :value");$query->bindParam(':table', $tableName);$query->bindParam(':column', $columnName);$query->bindParam(':value', $value);

                  PDO 會允許我像這樣綁定表名和列名嗎?似乎允許它,但即使我使用 PDO::PARAM_INT 或 PDO::PARAM_BOOL 作為數據類型,它也會在我的參數周圍加上引號.

                  如果這不起作用,我怎樣才能安全地轉義我的變量以便我可以在查詢中插入它們?

                  解決方案

                  很遺憾,您無法通過列名綁定參數.

                  您可以嘗試動態創建 SQL 命令:

                  $sql = "SELECT * FROM $tableName WHERE $columnName = :value";$query = $dbh->prepare($sql);$query->bindParam(':value', $value);

                  只要確保對來自其他地方的參數/變量進行清理,以防止 SQL 注入.在這種情況下,$value一定程度上是安全的,但 $tableName$columnName 不是 -- 再次,尤其是如果這些變量的值不是由 you 提供,而是由您的用戶/訪問者/等提供...

                  另外一件事;請避免使用 * 并命名您的列... 查看原因:

                  http://www.jasonvolpe.com/topics/sql/>

                  使用 SELECT * 時的性能問題?

                  在此處查看其他類似帖子:

                  為什么 ORDER BY 子句中的綁定參數不對結果進行排序?

                  如何設置 ORDER BY 參數使用準備好的 PDO 語句?

                  I am using PDO and want to do something like this:

                  $query = $dbh->prepare("SELECT * FROM :table WHERE :column = :value");
                  $query->bindParam(':table', $tableName);
                  $query->bindParam(':column', $columnName);
                  $query->bindParam(':value', $value);
                  

                  Will PDO allow me to bind the table name and the column name like this? It seems to allow it, but it puts quotes around my parameters even if I use PDO::PARAM_INT or PDO::PARAM_BOOL as the data type.

                  If this won't work, how can I safely escape my variables so that I can interpolate them in the query?

                  解決方案

                  Unfortunately, you can't bind parameters by column names.

                  What you could try is to dynamically create your SQL command:

                  $sql = "SELECT * FROM $tableName WHERE $columnName = :value";
                  $query = $dbh->prepare($sql);
                  $query->bindParam(':value', $value);
                  

                  Just make sure to sanitize your parameters/variables if they are coming from elsewhere, to prevent SQL Injection. In this case, $value is safe to a degree but $tableName and $columnName are not -- again, that is most especially if the values for these variables are not provided by you and instead by your users/vistors/etc...

                  One other thing; please avoid using * and name your columns instead... See some reasons why:

                  http://www.jasonvolpe.com/topics/sql/

                  Performance issue in using SELECT *?

                  See other similar posts here:

                  Why doesn't binding parameter in ORDER BY clause order the results?

                  How do I set ORDER BY params using prepared PDO statement?

                  這篇關于如何使用 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的訪問被拒絕)
                  <legend id='uLphR'><style id='uLphR'><dir id='uLphR'><q id='uLphR'></q></dir></style></legend>
                  • <small id='uLphR'></small><noframes id='uLphR'>

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

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

                            主站蜘蛛池模板: 四虎永久免费黄色影片 | 成年人黄色免费视频 | 在线永久看片免费的视频 | 国产福利在线小视频 | 情侣酒店偷拍一区二区在线播放 | 亚洲精品国产精品国自产在线 | 亚洲免费视频一区二区 | 亚洲区视频 | 亚洲精品一区二区三区中文字幕 | 99精品在线| 羞视频在线观看 | 欧美日韩高清在线一区 | 成人精品鲁一区一区二区 | 碰碰视频 | 免费一级毛片 | 成人在线精品 | 日韩中文一区二区三区 | 久久av一区二区三区 | 亚洲欧美国产精品久久 | 久久成人精品视频 | 91免费在线视频 | 日韩日韩日韩日韩日韩日韩日韩 | 欧美日韩国产精品激情在线播放 | 精品国产一二三区 | 综合久久av | 天堂亚洲网 | 日日骚av | 国产日韩欧美精品一区二区 | 91电影| 午夜精品在线 | 久草色播 | 亚洲成人福利 | 欧美一级久久 | 99视频在线播放 | 精品伊人久久 | 久夜精品| 成人免费一级 | 欧美国产激情二区三区 | 免费午夜视频 | 国产日韩一区二区三区 | 日韩精品一区二区三区在线播放 |