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

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

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

      1. <small id='k7isJ'></small><noframes id='k7isJ'>

      2. <tfoot id='k7isJ'></tfoot>
      3. 如何使用 PDO 獲取一行

        How to fetch a row with PDO(如何使用 PDO 獲取一行)

      4. <tfoot id='YjUmY'></tfoot><legend id='YjUmY'><style id='YjUmY'><dir id='YjUmY'><q id='YjUmY'></q></dir></style></legend>
          • <small id='YjUmY'></small><noframes id='YjUmY'>

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

                  <tbody id='YjUmY'></tbody>
                  本文介紹了如何使用 PDO 獲取一行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我盡量不感到沮喪,但我最近了解到 mysql_* 在 PHP 中已被棄用.我決定學習如何使用 PDO.

                  I'm trying not to get frustrated, but I've recently learned that mysql_* is deprecated in PHP. I've decided that I would learn how to use PDO.

                  今天下午我剛剛在看它,使用它連接到數據庫很容易,但后來我想用它獲取一行并將該行保存為由列名索引的數組(同樣的方式正如函數 mysql_fetch_array 所做的那樣).我想不出它來挽救我的生命.

                  I've just been looking at it this afternoon, and connecting to the database using it was easy, but then I wanted to fetch a row with it and save the row as an array indexed by the column names (the same way as the function mysql_fetch_array did). I can't figure it out to save my life.

                  我會發布我的代碼來澄清,我確信它很簡單(所有編程錯誤總是很簡單),但我肯定做錯了什么.

                  I'll post my code to clarify, and I'm sure it is something simple (all programming errors are always simple), but I am definitely doing something wrong.

                  // Connect to the database
                  $host    = $_PARAM["DatabaseServer"];
                  $db        = $_PARAM["MainDatabase"];
                  $dbuser    = $_PARAM["DatabaseUser"];
                  $dbpass    = $_PARAM["DatabasePass"];
                  try
                  {
                      $Database = new PDO("mysql:host=$host;dbname=$db", $dbuser, $dbpass);
                  }
                  catch (PDOException $e)
                  {
                      echo "There was an unexpected error. Please try again, or contact us with concerns";
                  }
                  
                  $stmt = $Database->prepare("SELECT * FROM users WHERE username=?");
                  $stmt->execute(array($sUserCook));
                  $row = $stmt->fetchAll(PDO::FETCH_ASSOC);
                  
                  echo $row["username"];
                  

                  推薦答案

                  fetchAll 做它所說的:它獲取查詢的所有結果.由于它獲取了大量結果,因此您將獲得一個索引數組.

                  fetchAll does what it says: it fetches all results for a query. Since it fetches a lot of results, you'll get an indexed array.

                  fetch 會執行您可能正在尋找的操作:它為查詢獲取一個結果.如果您要將 mysql_* 代碼轉換為 PDO,最快的方法是使用此方法而不是 mysql_fetch_assoc.

                  fetch does what you might be looking for if you want only one row: it fetches one result for a query. If you're converting mysql_* code to PDO, the quickest way would be to just use this method instead of mysql_fetch_assoc.

                  如果您仍然使用 fetchAll:您的代碼可能看起來像這樣:

                  If you're still going with fetchAll: your code would probably just look like this:

                  $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
                  foreach ($rows as $row) {
                      echo $row['username'];
                  }
                  

                  就像我說的,如果您只是將遺留代碼轉換為 PDO 代碼,將所有查詢更改為準備好的語句并替換以下內容可能會更容易:

                  Like I said, if you're just converting legacy code to PDO code, it might be easier to just change all queries to prepared statements and replace the following:

                  • mysql_fetch_assoc($result)
                    -> $stmt->fetch(PDO::FETCH_ASSOC)
                  • mysql_num_rows($result)
                    -> $stmt->rowCount()
                  • while ($row = mysql_fetch_assoc($result)) {}
                    -> foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {}

                  這篇關于如何使用 PDO 獲取一行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  <i id='mSPx6'><tr id='mSPx6'><dt id='mSPx6'><q id='mSPx6'><span id='mSPx6'><b id='mSPx6'><form id='mSPx6'><ins id='mSPx6'></ins><ul id='mSPx6'></ul><sub id='mSPx6'></sub></form><legend id='mSPx6'></legend><bdo id='mSPx6'><pre id='mSPx6'><center id='mSPx6'></center></pre></bdo></b><th id='mSPx6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mSPx6'><tfoot id='mSPx6'></tfoot><dl id='mSPx6'><fieldset id='mSPx6'></fieldset></dl></div>
                  <tfoot id='mSPx6'></tfoot>
                  <legend id='mSPx6'><style id='mSPx6'><dir id='mSPx6'><q id='mSPx6'></q></dir></style></legend>

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

                        <tbody id='mSPx6'></tbody>

                          • <bdo id='mSPx6'></bdo><ul id='mSPx6'></ul>
                          • 主站蜘蛛池模板: 亚洲精品日韩一区二区电影 | 亚洲国产精选 | 日韩在线播放第一页 | 国产女人与拘做受视频 | 精品国产18久久久久久二百 | 久久精品一区二区三区四区 | 99九色| 国产精品爱久久久久久久 | 神马影院一区二区三区 | 影视先锋av资源噜噜 | 淫片一级国产 | 中文天堂在线观看 | 亚洲最大的黄色网址 | 国产精品特级毛片一区二区三区 | 日日干夜夜操 | 精品一区二区三区四区视频 | 九九热这里 | 久久最新网址 | 18成人在线观看 | 久久久亚洲一区 | 成人免费视频在线观看 | 午夜影视免费片在线观看 | 久久久久久高潮国产精品视 | va精品| 国产97在线看 | 羞羞视频网站 | 国产韩国精品一区二区三区 | 日韩成人性视频 | 午夜免费看 | 大香在线伊779 | 亚洲精品久久久一区二区三区 | 久久青 | 国产黄色大片在线观看 | 久久99精品国产麻豆婷婷 | 国产亚洲精品一区二区三区 | 亚洲视频 欧美视频 | 天天拍天天射 | 欧洲尺码日本国产精品 | 婷婷丁香激情 | 日韩av啪啪网站大全免费观看 | 欧美国产精品久久久 |