欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

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

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

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

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

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

          1.php頁面在進行瀏覽時需要有php語言執(zhí)行的環(huán)境,本人用的是WampServer軟件,只要將項目復(fù)制到wampserver_phpwampwww該路徑下就可以執(zhí)行php語言。

          2.建立php類文件(mysql.php)進行具體的操作

          <?php /*設(shè)置內(nèi)容類型和編碼樣式*/ header("content-type:text/html;charset=utf-8"); /*對數(shù)據(jù)庫操作*/ class dbMysqli{     private $conn = null;     public $message = "";     /*設(shè)置錯誤接受機制*/     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ù)庫服務(wù)器,設(shè)置連接數(shù)據(jù)庫編碼*/     function __construct($host,$user,$pwd,$dbName,$charset){         //連接數(shù)據(jù)庫服務(wù)器選擇數(shù)據(jù)庫         $this->conn = new mysqli($host,$user,$pwd,$dbName);         if($this->conn === false){             $this->Message("連接數(shù)據(jù)庫失敗",false);             return false;         }else{             $this->Message("連接數(shù)據(jù)庫成功,選擇數(shù)據(jù)庫");         }         //設(shè)置連接編碼         if($this->conn->set_charset($charset)){             $this->Message("設(shè)置編碼成功");         }else{             $this->Message("設(shè)置編碼失敗",false);         }     }     /*查詢數(shù)據(jù)庫數(shù)據(jù)*/     public function MoreData($sql){         $sql = trim($sql);         /*檢查sql語言是否正確*/         $result = preg_match('/^select/i',$sql);         if($result){             //執(zhí)行sql語句             $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ù)庫地址、用戶名,密碼,數(shù)據(jù)庫名,編碼方式*/ $db = new dbMysqli('localhost','root','cly8','user','utf-8');

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

          <?php      header("content-type:text/html;charset=utf-8");     error_reporting(E_ALL);     //引入一個數(shù)據(jù)庫操作類     include_once 'mysql.php';     //查詢數(shù)據(jù)     $rs = $db->MoreData("select * from student"); ?> <html>     <head>         <meta charset="utf-8" />         <title>css3實現(xiàn)多彩動態(tài)漩渦線條特效動畫</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>編號</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.最后訪問路徑http://localhost/文件夾名/index.php

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

          想了解

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號