本文实例讲述了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 '- '.NL;
///* USING: mysql_fetch_object()
// ---------------------------
while( $row = mysql_fetch_object( $result ) ):
echo TB.'
- '.$row->Database.' '.NL; endwhile; //*/ /* USING: mysql_fetch_row() // ------------------------ while( $row = mysql_fetch_row( $result ) ): echo TB.'
- '.$row[0].' '.NL; endwhile; //*/ /* USING: mysql_fetch_assoc() // -------------------------- while( $row = mysql_fetch_assoc( $result ) ): echo TB.'
- '.$row['Database'].' '.NL; endwhile; //*/ echo '
希望本文所述对大家的php程序设计有所帮助。
ECTouch是上海商创网络科技有限公司推出的一套基于 PHP 和 MySQL 数据库构建的开源且易于使用的移动商城网店系统!应用于各种服务器平台的高效、快速和易于管理的网店解决方案,采用稳定的MVC框架开发,完美对接ecshop系统与模板堂众多模板,为中小企业提供最佳的移动电商解决方案。ECTouch程序源代码完全无加密。安装时只需将已集成的文件夹放进指定位置,通过浏览器访问一键安装,无需对已有










