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

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

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

      <tfoot id='OD8fX'></tfoot>

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

        如何在 PHP 中使用 mysqli_query()?

        How to use mysqli_query() in PHP?(如何在 PHP 中使用 mysqli_query()?)

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

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

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

              • <legend id='s5fAd'><style id='s5fAd'><dir id='s5fAd'><q id='s5fAd'></q></dir></style></legend>
                • <bdo id='s5fAd'></bdo><ul id='s5fAd'></ul>
                  本文介紹了如何在 PHP 中使用 mysqli_query()?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在用 PHP 編碼.我有以下 mySQL 表:

                  I'm coding in PHP. I have the following mySQL table:

                  CREATE TABLE `students` (
                    `ID` int(10) NOT NULL AUTO_INCREMENT,
                    `Name` varchar(255) DEFAULT NULL,
                    `Start` int(10) DEFAULT NULL,
                    `End` int(10) DEFAULT NULL,
                     PRIMARY KEY (`ID`)
                   ) ENGINE=InnoDB;
                  

                  我正在嘗試使用 PHP 中的 mysqli_query 函數(shù)來(lái)描述表.

                  I'm trying to use the mysqli_query function in PHP to DESCRIBE the table.

                  這是我的代碼:

                  $link = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DATABASE);
                  $result = mysqli_query($link,"DESCRIBE students");
                  

                  文檔說(shuō)對(duì)于成功的 SELECT、SHOW、DESCRIBE 或 EXPLAIN 查詢(xún),mysqli_query() 將返回 mysqli_result 對(duì)象.

                  The documentation says For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object.

                  但是從那里我不知道如何打印 $result 以便它顯示查詢(xún)結(jié)果.如果可能,我想打印 $result 使其看起來(lái)像:

                  But from there I don't know how to print $result so that it shows the query results. If possible I want to print $result so that it looks like:

                  +----------+--------------+------+-----+---------+----------------+
                  | Field    | Type         | Null | Key | Default | Extra          |
                  +----------+--------------+------+-----+---------+----------------+
                  | ID       | int(10)      | NO   | PRI | NULL    | auto_increment |
                  | Name     | varchar(255) | YES  |     | NULL    |                |
                  | Start    | int(10)      | YES  |     | NULL    |                |
                  | End      | int(10)      | YES  |     | NULL    |                |
                  +----------+--------------+------+-----+---------+----------------+ 
                  

                  我的另一個(gè)問(wèn)題是如何打印查詢(xún)SHOW CREATE TABLE Students.

                  My other question is how to print the query SHOW CREATE TABLE students.

                  $result = mysqli_query($link,"SHOW CREATE TABLE students");
                  

                  推薦答案

                  我不得不承認(rèn),mysqli_query() 手冊(cè)條目沒(méi)有包含關(guān)于如何獲取多行的清晰示例.可能是因?yàn)樘茁诽茁妨耍琍HP 人都知道幾十年了:

                  I have to admit, mysqli_query() manual entry doesn't contain a clean example on how to fetch multiple rows. May be it's because the routine is so routine, known to PHP folks for decades:

                  $result = $link->query("DESCRIBE students");
                  while ($row = $result->fetch_assoc()) {
                      // to print all columns automatically:
                      foreach ($row as $value) {
                          echo "<td>$value</td>";
                          // OR to print each column separately:
                          echo "<td>",$row['Field'],"</td><td>",$row['Type'],"</td>
                  ";
                      }
                  }
                  

                  如果要打印列標(biāo)題,必須先將數(shù)據(jù)選入嵌套數(shù)組,然后使用第一行的鍵:

                  In case you want to print the column titles, you have to select your data into a nested array first and then use keys of the first row:

                  // getting all the rows from the query
                  // note that handy feature of OOP syntax
                  $data = $link->query("DESC students")->fetch_all(MYSQLI_ASSOC);
                  // getting keys from the first row
                  $header = array_keys(reset($data));
                  // printing them
                  foreach ($header as $value) {
                      echo "<td>$value</td>";
                  }
                  // finally printing the data
                  foreach ($data as $row) {
                      foreach ($row as $value) {
                          echo "<td>$value</td>";
                      }
                  }
                  

                  某些主機(jī)可能不支持 fetch_all() 函數(shù).在這種情況下,按照通常的方式填充 $data 數(shù)組:

                  Some hosts may have no support for the fetch_all() function. In such a case, fill the $data array the usual way:

                  $data = [];
                  $result = $link->query("DESC students");
                  while ($row = $result->fetch_assoc())
                  {
                      $data[] = $row;
                  }
                  

                  我必須補(bǔ)充兩個(gè)重要的說(shuō)明.

                  1. 您必須將 mysqli 配置為自動(dòng)拋出錯(cuò)誤,而不是手動(dòng)檢查每個(gè) mysqli 語(yǔ)句的錯(cuò)誤.為此,在 before mysqli_connect() 之前添加這一行:

                   mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
                  

                • 最重要的提示:mysql_query()不同,mysqli_query()的用途非常有限.僅當(dāng)查詢(xún)中不使用任何變量時(shí),您才可以使用此函數(shù).如果要使用任何 PHP 變量,則永遠(yuǎn)不要使用 mysqli_query(),但始終堅(jiān)持準(zhǔn)備好的聲明,如下所示:

                • The most important note: unlike mysql_query(), mysqli_query() has a very limited use. You may use this function only if no variables are going to be used in the query. If any PHP variable is going to be used, you should never use mysqli_query(), but always stick to prepared statements, like this:

                   $stmt = $mysqli->prepare("SELECT * FROM students WHERE class=?");
                   $stmt->bind_param('i', $class);
                   $stmt->execute();
                   $data = $stmt->get_result()->fetch_all();
                  

                • 這有點(diǎn)羅嗦,我不得不承認(rèn).為了減少代碼量,您可以使用 PDO 或采用簡(jiǎn)單的輔助函數(shù)來(lái)完成所有工作里面的準(zhǔn)備/綁定/執(zhí)行業(yè)務(wù):

                  It's a bit wordy, I have to admit. In order to reduce the amount of code you can either use PDO or adopt a simple helper function to do all the prepare/bind/execute business inside:

                  $sql = "SELECT * FROM students WHERE class=?";
                  $data = prepared_select($mysqli, $sql, [$class])->fetch_all();
                  

                  這篇關(guān)于如何在 PHP 中使用 mysqli_query()?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調(diào)用未定義的函數(shù) mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準(zhǔn)備好的語(yǔ)句問(wèn)題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個(gè)結(jié)果)
                  PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                  How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類(lèi)型?)
                    <tbody id='840ab'></tbody>
                • <small id='840ab'></small><noframes id='840ab'>

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

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

                      <tfoot id='840ab'></tfoot>

                            主站蜘蛛池模板: av色噜噜 | 欧美一区二区三区 | 日本电影网站 | 中文字幕一区二区三区日韩精品 | 国产欧美一区二区久久性色99 | 久久久久久99 | 欧美福利一区 | 国产欧美久久精品 | 国产精品视频网 | 亚洲国产精品99久久久久久久久 | 中文精品视频 | 性一交一乱一透一a级 | 四虎影院新网址 | 男人的天堂久久 | 五月天婷婷综合 | 日日噜噜噜夜夜爽爽狠狠视频97 | 可以免费看的毛片 | 免费人成在线观看网站 | 欧美日韩高清一区二区三区 | 日日网| 国产一级大片 | 综合色婷婷 | 午夜精品三区 | 综合久久综合久久 | 在线色网 | 亚洲国产日韩欧美 | www午夜视频| 亚洲一区二区三区在线播放 | 久久精品国产久精国产 | 日本亚洲一区二区 | 99视频 | 成人免费大片黄在线播放 | 欧美中文字幕在线观看 | 五月激情久久 | 亚洲精品久久久一区二区三区 | 成人av影院 | 欧美午夜影院 | 一区二区精品视频 | 狠狠的干 | 在线男人天堂 | 我要看黄色录像一级片 |