您好,欢迎访问一九零五行业门户网

PHP如何列出MySQL中所有数据库

这篇文章主要介绍了php列出mysql中所有数据库的方法,涉及php操作数据库的技巧,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了php列出mysql中所有数据库的方法。具体如下:
php代码如下:
<?phpdefine( '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 listecho '<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 connectionmysql_free_result( $result );mysql_close( $conn ); ?>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php中foreach()的使用方法
php大规模数据提交的方法
php基于socket实现udp通信的方法
以上就是php如何列出mysql中所有数据库的详细内容。
其它类似信息

推荐信息