PHP列出MySQL中所有數(shù)據(jù)庫的方法
更新時間:2015年03月12日 12:00:05 作者:鑒客
這篇文章主要介紹了PHP列出MySQL中所有數(shù)據(jù)庫的方法,涉及php操作數(shù)據(jù)庫的技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了PHP列出MySQL中所有數(shù)據(jù)庫的方法。分享給大家供大家參考。具體如下:
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 ); ?>
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
PHP中執(zhí)行MYSQL事務(wù)解決數(shù)據(jù)寫入不完整等情況
事務(wù)可以進行模擬SQL操作,當(dāng)所有的SQL都操作成功的時候才進行SQL操作,只要有一個操作失敗就回滾當(dāng)前事務(wù)的所有SQL操作,避免出現(xiàn)上面描述中出現(xiàn)的數(shù)據(jù)寫入不完整等情況2014-01-01Windows環(huán)境下安裝PHP Pear的方法圖文教程
這篇文章主要介紹了Windows環(huán)境下安裝PHP Pear的方法,結(jié)合圖文形式詳細說明了Windows環(huán)境下安裝PHP Pear的相關(guān)命令與操作技巧,需要的朋友可以參考下2019-07-07PHP使用內(nèi)置函數(shù)file_put_contents寫入文件及追加內(nèi)容的方法
這篇文章主要介紹了PHP使用內(nèi)置函數(shù)file_put_contents寫入文件及追加內(nèi)容的方法,結(jié)合實例形式分析了file_put_contents函數(shù)通過參數(shù)設(shè)置實現(xiàn)寫入文件及追加內(nèi)容的相關(guān)技巧,非常簡單實用,需要的朋友可以參考下2015-12-12