php語言查詢Mysql數(shù)據(jù)庫內(nèi)容的方法:首先php頁面在進(jìn)行瀏覽時(shí)需要有php語言執(zhí)行的環(huán)境;然后建立php類文件【mysql.php】進(jìn)行具體的操作;接著建立頁面文件【index.php】進(jìn)行接收數(shù)據(jù);最后訪問路徑即可。
創(chuàng)新互聯(lián)專注于岳塘網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供岳塘營銷型網(wǎng)站建設(shè),岳塘網(wǎng)站制作、岳塘網(wǎng)頁設(shè)計(jì)、岳塘網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造岳塘網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供岳塘網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
【相關(guān)學(xué)習(xí)推薦:mysql教程】
php語言查詢Mysql數(shù)據(jù)庫內(nèi)容的方法:
1.php頁面在進(jìn)行瀏覽時(shí)需要有php語言執(zhí)行的環(huán)境,本人用的是WampServer軟件,只要將項(xiàng)目復(fù)制到wampserver_php\\wamp\\www\\
該路徑下就可以執(zhí)行php語言。
2.建立php類文件(mysql.php)進(jìn)行具體的操作
<?php /*設(shè)置內(nèi)容類型和編碼樣式*/ header("content-type:text/html;charset=utf-8"); /*對數(shù)據(jù)庫操作*/ 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ù)庫服務(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)進(jìn)行接收數(shù)據(jù)
<?php header("content-type:text/html;charset=utf-8"); error_reporting(E_ALL); //引入一個(gè)數(shù)據(jù)庫操作類 include_once 'mysql.php'; //查詢數(shù)據(jù) $rs = $db->MoreData("select * from student"); ?> <html> <head> <meta charset="utf-8" /> <title>css3實(shí)現(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
想了解更多相關(guān)學(xué)習(xí),敬請關(guān)注php培訓(xùn)欄目!
網(wǎng)站題目:php語言如何查詢Mysql數(shù)據(jù)庫內(nèi)容
文章URL:http://www.rwnh.cn/article22/cjphcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、小程序開發(fā)、網(wǎng)站內(nèi)鏈、企業(yè)建站、網(wǎng)站收錄、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)