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

<tfoot id='hPj98'></tfoot>

  • <legend id='hPj98'><style id='hPj98'><dir id='hPj98'><q id='hPj98'></q></dir></style></legend>

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

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

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

        PDO bindParam 問題

        PDO bindParam issue(PDO bindParam 問題)
          • <bdo id='MuXOm'></bdo><ul id='MuXOm'></ul>

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

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

              <legend id='MuXOm'><style id='MuXOm'><dir id='MuXOm'><q id='MuXOm'></q></dir></style></legend>

                  <tfoot id='MuXOm'></tfoot>

                    <tbody id='MuXOm'></tbody>

                  本文介紹了PDO bindParam 問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  可能的重復(fù):
                  PHP PDO 語句可以接受表名作為參數(shù)嗎?

                  我的班級中有一個函數(shù)遇到了一些麻煩.這里的功能

                  I have a function in my class which is doing some trouble. Here the function

                  function insert($table,$column = array(),$value = array())
                  {
                      $array1 = implode(",", $column);
                      $array2 = implode(",", $value);
                  
                      try 
                      { 
                          $sql = $this->connect->prepare("INSERT INTO :table (:date1) VALUES (:date2)");  
                          $sql->bindParam(':table',$table, PDO::PARAM_STR);
                          $sql->bindParam(':data1',$array1, PDO::PARAM_STR);
                          $sql->bindParam(':data2',$array2, PDO::PARAM_STR);
                  
                          $sql->execute();
                  
                      }  
                      catch(PDOException $e) 
                      {  
                          echo $e->getMessage();  
                      }  
                  }
                  

                  我調(diào)用函數(shù):

                  -> insert('coupons',array('categorie','name','link','code','id'),array('test11','test','test','test','NULL'));
                  

                  我得到的錯誤是:

                  警告:PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: 無效的參數(shù)號:參數(shù)未在 C:xampphtdocsMYFRAMEWORKlibdatabase.class.php 中定義在第 46 行

                  Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:xampphtdocsMYFRAMEWORKlibdatabase.class.php on line 46

                  第 46 行是:

                  $sql->execute();
                  

                  所以現(xiàn)在我真的不明白問題出在哪里.有什么指點嗎?

                  So now I don't really see where the issue is. Any pointers?

                  推薦答案

                  PDO 綁定值數(shù)據(jù),而不是表名和列名.

                  您誤解了綁定的使用.您不能使用 PDO 綁定表名和列名.您綁定數(shù)據(jù)以插入 INTO 這些列.您需要使用字符串操作構(gòu)造 SQL 以包含表名和列.

                  PDOs bind value data, not table and column names.

                  You are misunderstanding the use of bindings. You cannot bind table and column names with PDO. You bind data to insert INTO those columns. You need to construct the SQL to include the table names and columns using string operations.

                  我已將您的 $column 和 $value 重命名為 $column_array, $value_array 以說明它們是什么,并假設(shè)每個都是一個簡單的數(shù)組:$column_array = array('column1', 'column2', ...) 等

                  I've renamed your $column and $value to $column_array, $value_array to make it clear what they are, and assumed that each is a simple array: $column_array = array('column1', 'column2', ...) etc.

                  $placeholders = array_map(function($col) { return ":$col"; }, $column_array);
                  
                  $bindvalues = array_combine($placeholders , $value_array);
                  

                  $placeholders 現(xiàn)在看起來像這樣:

                  $placeholders now looks like this:

                  $placeholders = array(
                          ':column1',
                          ':column2',
                           ...
                      );
                  

                  $bindvalues 現(xiàn)在看起來像這樣:

                  $bindvalues now looks like this:

                  $bindvalues = array(
                          ':column1'=>'value1',
                          ':column2'=>'value2',
                           ...
                      );
                  

                  構(gòu)建、準備、執(zhí)行

                  $sql = $this->connect->prepare("INSERT INTO $table (" .implode(",", $column_array) .") VALUES (". implode(",", $placeholders) . ")";
                  

                  這將為您提供一份準備好的聲明:

                  This will give you a prepared statement of the form:

                  $sql = INSERT INTO table_name (column1, column2, ...) VALUES (:column1, :column2, ...)
                  

                  然后您可以執(zhí)行準備好的語句并將 $values 作為參數(shù)傳遞.

                  You can then execute the prepared statement and pass the $values as an argument.

                  $sql->execute($bindValues);
                  

                  注意:

                  • 必須提到的一個警告.確保您的原始數(shù)據(jù)已針對 SQL 注入進行了清理. PDO 會處理綁定值的問題,但是如果您從 $_POST 數(shù)據(jù)構(gòu)建列,這很容易受到攻擊,需要進行消毒.
                  • Note:

                    • One caveat that must be mentioned. Make sure that your original data has been sanitized against SQL Injection. PDO's take care of that for the bound values, but if you are constructing the columns from, say, $_POST data this is vulnerable and needs to be sanitized.
                    • 這篇關(guān)于PDO bindParam 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

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

                  <tfoot id='55ZCI'></tfoot>

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

                      <small id='55ZCI'></small><noframes id='55ZCI'>

                          <legend id='55ZCI'><style id='55ZCI'><dir id='55ZCI'><q id='55ZCI'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 日韩在线一区二区 | 欧美一区二区视频 | 亚洲一区二区免费视频 | 亚洲精选一区 | 免费毛片www com cn | 高清免费av | 亚洲a网 | 国产精品综合视频 | jⅰzz亚洲 | 一级做a爰片性色毛片 | 亚洲男人天堂 | 91五月婷蜜桃综合 | 中文字幕一区二区三区四区五区 | 午夜影院| 久久久91精品国产一区二区三区 | 99热这里都是精品 | 呦呦在线视频 | 在线久草 | 欧美精品一区二区三区在线播放 | 中文字幕国产视频 | 99精品99| 国产黄色麻豆视频 | 久久久999免费视频 999久久久久久久久6666 | 国产一区二区三区久久 | 国产精品久久久久久久久久免费看 | 国产成人高清成人av片在线看 | 精品一区二区三区av | 日韩欧美一区二区三区免费观看 | 国产网站在线免费观看 | 欧美成人激情 | 久久综合伊人 | 久久久久国产 | 久久成人国产 | 在线视频 欧美日韩 | 久草在线免费资源 | www免费视频 | 精品视频在线播放 | 99这里只有精品视频 | 国产1区2区3区 | 特黄视频 | 国产精品久久久久一区二区 |