PHP列出MySQL中所有數(shù)據(jù)庫(kù)的方法
更新時(shí)間:2015年03月12日 12:00:05 作者:鑒客
這篇文章主要介紹了PHP列出MySQL中所有數(shù)據(jù)庫(kù)的方法,涉及php操作數(shù)據(jù)庫(kù)的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了PHP列出MySQL中所有數(shù)據(jù)庫(kù)的方法。分享給大家供大家參考。具體如下:
PHP代碼如下:
<?php
define( 'NL', "\n" );
define( 'TB', ' ' );
// connecting to MySQL.
$conn = @mysql_connect( 'localhost', 'username', 'password' )
or die( mysql_errno().': '.mysql_error().NL );
// attempt to get a list of MySQL databases
// already set up in my account. This is done
// using the PHP function: mysql_list_dbs()
$result = mysql_list_dbs( $conn );
// Output the list
echo '<ul class="projects">'.NL;
///* USING: mysql_fetch_object()
// ---------------------------
while( $row = mysql_fetch_object( $result ) ):
echo TB.'<li>'.$row->Database.'</li>'.NL;
endwhile;
//*/
/* USING: mysql_fetch_row()
// ------------------------
while( $row = mysql_fetch_row( $result ) ):
echo TB.'<li>'.$row[0].'</li>'.NL;
endwhile;
//*/
/* USING: mysql_fetch_assoc()
// --------------------------
while( $row = mysql_fetch_assoc( $result ) ):
echo TB.'<li>'.$row['Database'].'</li>'.NL;
endwhile;
//*/
echo '</ul>'.NL;
// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP中mysqli_get_server_version()的實(shí)例用法
在本篇文章里小編給大家分享的是關(guān)于PHP中mysqli_get_server_version()用法以及相關(guān)知識(shí)點(diǎn),需要的朋友們可以參考下。2020-02-02
PHP中怎樣保持SESSION不過(guò)期 原理及方案介紹
本文主要討論WEB SESSION,其一般有兩種:客戶端SESSION和服務(wù)器端SESSION,后一種最常見(jiàn)的屬于Java Beans提供的2013-08-08
PHP使用DirectoryIterator顯示下拉文件列表的方法
這篇文章主要介紹了PHP使用DirectoryIterator顯示下拉文件列表的方法,涉及php使用DirectoryIterator操作文件的技巧,需要的朋友可以參考下2015-03-03
PHP+Tidy-完美的XHTML糾錯(cuò)+過(guò)濾
PHP+Tidy-完美的XHTML糾錯(cuò)+過(guò)濾...2007-04-04
PHP內(nèi)置的Math函數(shù)效率測(cè)試
這篇文章主要介紹了PHP內(nèi)置的Math函數(shù)效率測(cè)試,以實(shí)例形式測(cè)試了相關(guān)的PHP內(nèi)置數(shù)學(xué)運(yùn)算函數(shù)的執(zhí)行時(shí)間,分析其運(yùn)行效率,需要的朋友可以參考下2014-12-12
php上傳圖片到指定位置路徑保存到數(shù)據(jù)庫(kù)的具體實(shí)現(xiàn)
本文為大家介紹下php上傳圖片到指定位置路徑保存到數(shù)據(jù)庫(kù)的具體實(shí)現(xiàn),感興趣的朋友不要錯(cuò)過(guò)2013-12-12

