您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)php網(wǎng)站如何查看數(shù)據(jù)庫,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
php網(wǎng)站查看數(shù)據(jù)庫的方法:
推薦:php服務(wù)器
連接數(shù)據(jù)庫代碼:
<?php define("DB_HOST","localhost"); define("DB_USER","root"); define("DB_PWD",""); define("DB_NAME","wordpress4"); $conn = @mysql_connect(DB_HOST,DB_USER,DB_PWD) or die("連接服務(wù)器出錯:".mysql_error()); @mysql_select_db(DB_NAME) or die("連接數(shù)據(jù)庫出錯:".mysql_error()); @mysql_query('SET NAMES UTF8'); ?>
讀取數(shù)據(jù)庫信息代碼:
$result = mysql_query("select * from wp_wf order by timer02 desc limit 0,50");//獲取最新50條數(shù) while($row = mysql_fetch_array($result))//轉(zhuǎn)成數(shù)組,且返回第一條數(shù)據(jù),當(dāng)不是一個對象時候退出 { echo ' <div class="cp_haoma_list cat-list"> <h3>數(shù)據(jù)詳情<label>'.$row['number02'].'</label></h3> <div class="haoma_con"><span>'. str_ireplace(",","</span><span>",$row['datar02']) .'</span> </div> </div>'; }
關(guān)閉數(shù)據(jù)庫代碼:
mysql_close($conn);
三段代碼結(jié)合在一起,就可以實現(xiàn) PHP讀取數(shù)據(jù)庫并顯示到網(wǎng)站前臺。代碼如下:
<?php require "conn.php";//連接數(shù)據(jù)庫 $result = mysql_query("select * from wp_kaijiangwf order by timer02 desc limit 0,50");//最新50條數(shù) while($row = mysql_fetch_array($result))//轉(zhuǎn)成數(shù)組,且返回第一條數(shù)據(jù),當(dāng)不是一個對象時候退出 { echo ' <div class="cp_haoma_list cat-list"> <h3>數(shù)據(jù)詳情<label>'.$row['number02'].'</label></h3> <div class="haoma_con"><span>'. str_ireplace(",","</span><span>",$row['datar02']) .'</span> </div> </div>'; } mysql_close($conn);// 關(guān)閉數(shù)據(jù)庫 ?>
關(guān)于php網(wǎng)站如何查看數(shù)據(jù)庫就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。