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

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

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

    <legend id='cOkwn'><style id='cOkwn'><dir id='cOkwn'><q id='cOkwn'></q></dir></style></legend>
      <bdo id='cOkwn'></bdo><ul id='cOkwn'></ul>

        <tfoot id='cOkwn'></tfoot>

        如何在php pdo中使用where子句多次調用函數?

        how to call a function multiple times with where clause in php pdo?(如何在php pdo中使用where子句多次調用函數?)

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

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

            • <legend id='zAZKS'><style id='zAZKS'><dir id='zAZKS'><q id='zAZKS'></q></dir></style></legend>
                <tbody id='zAZKS'></tbody>
                1. <i id='zAZKS'><tr id='zAZKS'><dt id='zAZKS'><q id='zAZKS'><span id='zAZKS'><b id='zAZKS'><form id='zAZKS'><ins id='zAZKS'></ins><ul id='zAZKS'></ul><sub id='zAZKS'></sub></form><legend id='zAZKS'></legend><bdo id='zAZKS'><pre id='zAZKS'><center id='zAZKS'></center></pre></bdo></b><th id='zAZKS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zAZKS'><tfoot id='zAZKS'></tfoot><dl id='zAZKS'><fieldset id='zAZKS'></fieldset></dl></div>
                2. 本文介紹了如何在php pdo中使用where子句多次調用函數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我是 php 的新手,正在努力學習它為什么你們和女孩需要原諒我問了很多!

                  I am new to php and trying hard to learn its why you guys and gals need to Forgive me for asking a lot!

                  這是我的問題;

                  我試圖多次調用帶有 where 子句的函數,我已經閱讀了幾乎所有的帖子和示例,但仍然不明白該怎么做.

                  I am trying to call a function with where clause multiple times, I have read allmost all posts and examples still didn't understand how to do it.

                  我認為一個例子比我能寫的任何簡介都更有用.

                  I tought that An example will be more useful than any blurb I can write.

                  這是我嘗試創建并多次使用的函數:

                  Here is the function I am trying to create and use it multiple times :

                  function getTable($tableName, $clause) {
                          $stmt = $pdo->prepare("SELECT * FROM ".$tableName." WHERE ".$clause." = :".$clause);
                          $stmt->bindParam(":$clause", $clause, PDO::PARAM_STR);
                          $stmt->execute();
                          if($stmt->rowCount() > 0){
                              return true;
                          }else{
                              return false;
                          }
                      return $stmt;
                  }
                  

                  我不確定我的功能是否安全或正確.

                  I am not sure if my fucntion is safe or its rigth.

                  這就是我試圖調用函數的方式,我不知道如何調用表名和 where 子句以及如何打開 while 循環.

                  AND this is how I am trying to call function, which I dont know how to call table name and where clause and how to turn while loop.

                  getTable('posts');
                  

                  如果你能給出一個創建和調用函數的例子,我將不勝感激,謝謝

                  If you give an example of creating and caling function, I would be grateful, Thanks

                  推薦答案

                  不,你的函數不安全.此外,它只是無用的.沒有任何用例可以像這樣使用它 getTable('posts');.對于其他一切,最好允許完整的 SQL 語法,而不是某些有限的子集.

                  Nope, your function is not safe. Moreover it is just useless. There is no use case where you would use it like this getTable('posts');. And for the everything else it is much better to allow the full SQL syntax, not some limited subset.

                  我能想到的最簡單但最強大的 PDO 函數是一個接受 PDO 對象、SQL 查詢和帶有輸入變量的數組的函數.返回 PDO 語句.我在關于 PDO 輔助函數的文章中寫到了這樣的函數.所以這是代碼:

                  The simplest yet most powerful PDO function I can think of is a function that accepts a PDO object, an SQL query, and array with input variables. A PDO statement is returned. I wrote about such function in my article about PDO helper functions. So here is the code:

                  function pdo($pdo, $sql, $args = NULL)
                  {
                      if (!$args)
                      {
                           return $pdo->query($sql);
                      }
                      $stmt = $pdo->prepare($sql);
                      $stmt->execute($args);
                      return $stmt;
                  } 
                  

                  使用此功能,您將能夠使用任意數量的 WHERE 條件運行任何查詢,并獲得多種不同格式的結果.以下是上述文章中的一些示例:

                  With this function you will be able to run any query, with any number of WHERE conditions, and get results in many different formats. Here are some examples from the article mentioned above:

                  // getting the number of rows in the table
                  $count = pdo($pdo, "SELECT count(*) FROM users")->fetchColumn();
                  
                  // the user data based on email
                  $user = pdo($pdo, "SELECT * FROM users WHERE email=?", [$email])->fetch();
                  
                  // getting many rows from the table
                  $data = pdo($pdo, "SELECT * FROM users WHERE salary > ?", [$salary])->fetchAll();
                  
                  // getting the number of affected rows from DELETE/UPDATE/INSERT
                  $deleted = pdo($pdo, "DELETE FROM users WHERE id=?", [$id])->rowCount();
                  
                  // insert
                  pdo($pdo, "INSERT INTO users VALUES (null, ?,?,?)", [$name, $email, $password]);
                  
                  // named placeholders are also welcome though I find them a bit too verbose
                  pdo($pdo, "UPDATE users SET name=:name WHERE id=:id", ['id'=>$id, 'name'=>$name]);
                  
                  // using a sophisticated fetch mode, indexing the returned array by id
                  $indexed = pdo($pdo, "SELECT id, name FROM users")->fetchAll(PDO::FETCH_KEY_PAIR);
                  

                  特別適合你,這里是 while 的例子,雖然這個方法被認為是笨拙和過時的:

                  Special for you, here is the while example, though this method is considered clumsy and outdated:

                  $stmt = pdo($pdo,"SELECT * FROM tableName WHERE field = ?",[$value]);
                  while ($row = $stmt->fetch()) {
                      echo $row['name'];
                  }
                  

                  這篇關于如何在php pdo中使用where子句多次調用函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='ifCCO'><style id='ifCCO'><dir id='ifCCO'><q id='ifCCO'></q></dir></style></legend><tfoot id='ifCCO'></tfoot>
                      • <i id='ifCCO'><tr id='ifCCO'><dt id='ifCCO'><q id='ifCCO'><span id='ifCCO'><b id='ifCCO'><form id='ifCCO'><ins id='ifCCO'></ins><ul id='ifCCO'></ul><sub id='ifCCO'></sub></form><legend id='ifCCO'></legend><bdo id='ifCCO'><pre id='ifCCO'><center id='ifCCO'></center></pre></bdo></b><th id='ifCCO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ifCCO'><tfoot id='ifCCO'></tfoot><dl id='ifCCO'><fieldset id='ifCCO'></fieldset></dl></div>

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

                          <tbody id='ifCCO'></tbody>
                          <bdo id='ifCCO'></bdo><ul id='ifCCO'></ul>
                          • 主站蜘蛛池模板: 在线观看中文字幕一区二区 | 久久小视频 | 成年人在线视频 | 国产精品日韩欧美一区二区 | 亚洲欧美国产精品久久 | 国产男女视频网站 | 黄色大片网站 | 一级毛片在线看 | 夜久久 | 日韩欧美专区 | 欧美在线观看一区 | 亚洲国产精品成人无久久精品 | 国产女人精品视频 | 91精品国产91久久综合桃花 | 在线看av网址 | 国产成人99久久亚洲综合精品 | 日本成人中文字幕在线观看 | 91久久国产综合久久91精品网站 | 国产成人jvid在线播放 | 国产精品美女久久久久久不卡 | 一区| h片在线播放 | 国产高清在线精品一区二区三区 | 瑟瑟激情 | 欧美精品在线一区二区三区 | 久久久av| 日韩一区二区三区视频 | 久久久久久久国产精品视频 | 国产精品久久久久久久久免费桃花 | 久久久久久国产精品 | 成人在线中文字幕 | 精品视频一区二区三区在线观看 | 在线免费看黄 | 91天堂网 | 欧美日韩一二三区 | 毛片久久久 | 91精品国产乱码久久久久久 | 亚洲午夜视频 | 国产成人精品久久 | 色黄爽| 激情五月婷婷在线 |