本文实例讲述了php列出mysql中所有数据库的方法。分享给大家供大家参考。具体如下:
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程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!