欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

          php語(yǔ)言如何查詢Mysql數(shù)據(jù)庫(kù)內(nèi)容

          php語(yǔ)言查詢Mysql數(shù)據(jù)庫(kù)內(nèi)容的方法:首先php頁(yè)面在進(jìn)行瀏覽時(shí)需要有php語(yǔ)言執(zhí)行的環(huán)境;然后建立php類(lèi)文件【mysql.php】進(jìn)行具體的操作;接著建立頁(yè)面文件【index.php】進(jìn)行接收數(shù)據(jù);最后訪問(wèn)路徑即可。

          創(chuàng)新互聯(lián)專注于岳塘網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供岳塘營(yíng)銷(xiāo)型網(wǎng)站建設(shè),岳塘網(wǎng)站制作、岳塘網(wǎng)頁(yè)設(shè)計(jì)、岳塘網(wǎng)站官網(wǎng)定制、小程序開(kāi)發(fā)服務(wù),打造岳塘網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供岳塘網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。

          【相關(guān)學(xué)習(xí)推薦:mysql教程】

          php語(yǔ)言查詢Mysql數(shù)據(jù)庫(kù)內(nèi)容的方法:

          1.php頁(yè)面在進(jìn)行瀏覽時(shí)需要有php語(yǔ)言執(zhí)行的環(huán)境,本人用的是WampServer軟件,只要將項(xiàng)目復(fù)制到wampserver_php\\wamp\\www\\該路徑下就可以執(zhí)行php語(yǔ)言。

          2.建立php類(lèi)文件(mysql.php)進(jìn)行具體的操作

          <?php
          /*設(shè)置內(nèi)容類(lèi)型和編碼樣式*/
          header("content-type:text/html;charset=utf-8");
          /*對(duì)數(shù)據(jù)庫(kù)操作*/
          class dbMysqli{
              private $conn = null;
              public $message = "";
              /*設(shè)置錯(cuò)誤接受機(jī)制*/
              function Message($mes,$flag=true){
                  if($flag){
                      $this->message .="<div style='color:green;font-size:12px;'>".$mes."</div>";
                  }else{
                      $this->message .="<div style='color:green;font-size:12px;'>".$mes."</div>";
                  }
              }
            /*連接數(shù)據(jù)庫(kù)服務(wù)器,設(shè)置連接數(shù)據(jù)庫(kù)編碼*/
              function __construct($host,$user,$pwd,$dbName,$charset){
                  //連接數(shù)據(jù)庫(kù)服務(wù)器選擇數(shù)據(jù)庫(kù)
                  $this->conn = new mysqli($host,$user,$pwd,$dbName);
                  if($this->conn === false){
                      $this->Message("連接數(shù)據(jù)庫(kù)失敗",false);
                      return false;
                  }else{
                      $this->Message("連接數(shù)據(jù)庫(kù)成功,選擇數(shù)據(jù)庫(kù)");
                  }
                  //設(shè)置連接編碼
                  if($this->conn->set_charset($charset)){
                      $this->Message("設(shè)置編碼成功");
                  }else{
                      $this->Message("設(shè)置編碼失敗",false);
                  }
              }
              /*查詢數(shù)據(jù)庫(kù)數(shù)據(jù)*/
              public function MoreData($sql){
                  $sql = trim($sql);
                  /*檢查sql語(yǔ)言是否正確*/
                  $result = preg_match('/^select/i',$sql);
                  if($result){
                      //執(zhí)行sql語(yǔ)句
                      $rs = $this->conn->query($sql);
                      if($rs === false){
                          $this->Message("執(zhí)行'".$sql."'失敗,失敗原因:".$this->conn->error,false);
                          return false;
                      }else{
                          $this->Message("執(zhí)行'".$sql."'成功");
                          $RS = $rs->fetch_all(MYSQL_ASSOC);
                          $rs->free();
                          return $RS;
                      }
                  }else{
                      $this->Message("執(zhí)行'".$sql."'失敗",false);
                      return false;
                  }
              }
          }
          /*鏈接數(shù)據(jù)庫(kù)地址、用戶名,密碼,數(shù)據(jù)庫(kù)名,編碼方式*/
          $db = new dbMysqli('localhost','root','cly8','user','utf-8');

          3.建立頁(yè)面文件(index.php)進(jìn)行接收數(shù)據(jù)

          <?php 
              header("content-type:text/html;charset=utf-8");
              error_reporting(E_ALL);
              //引入一個(gè)數(shù)據(jù)庫(kù)操作類(lèi)
              include_once 'mysql.php';
              //查詢數(shù)據(jù)
              $rs = $db->MoreData("select * from student");
          ?>
          <html>
              <head>
                  <meta charset="utf-8" />
                  <title>css3實(shí)現(xiàn)多彩動(dòng)態(tài)漩渦線條特效動(dòng)畫(huà)</title>
              </head>
              <style>
              table{
              font-family: verdana,arial,sans-serif;
              font-size:11px;
              color:#333333;
              border-width: 1px;
              border-color: #666666;
              border-collapse: collapse;
              }
              table th {
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #666666;
              background-color: #dedede;
              }
              table td {
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #666666;
              background-color: #ffffff;
              }
              </style>
          <body>
              <table>
                  <tr>
                      <th>編號(hào)</th>
                      <th>姓名</th>
                      <th>密碼</th>
                  </tr>
                  <?php foreach($rs as $val) {?>
                  <tr>
                      <td><?php echo $val['Sid'];?></td>
                      <td><?php echo $val['Sname'];?></td>
                      <td><?php echo $val['Password'];?></td>
                  </tr>
                  <?php }?>
              </table>
          </body>
          </html>

          4.最后訪問(wèn)路徑http://localhost/文件夾名/index.php

          想了解更多相關(guān)學(xué)習(xí),敬請(qǐng)關(guān)注php培訓(xùn)欄目!

          網(wǎng)站題目:php語(yǔ)言如何查詢Mysql數(shù)據(jù)庫(kù)內(nèi)容
          文章URL:http://chinadenli.net/article22/cjphcc.html

          成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開(kāi)發(fā)、小程序開(kāi)發(fā)網(wǎng)站內(nèi)鏈、企業(yè)建站、網(wǎng)站收錄網(wǎng)站維護(hù)

          廣告

          聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

          成都網(wǎng)站建設(shè)公司