>  기사  >  백엔드 개발  >  MySQL_php 팁의 모든 데이터베이스를 나열하는 PHP 방법

MySQL_php 팁의 모든 데이터베이스를 나열하는 PHP 방법

WBOY
WBOY원래의
2016-05-16 20:21:301265검색

이 기사의 예에서는 PHP가 MySQL의 모든 데이터베이스를 나열하는 방법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 내용은 다음과 같습니다.

PHP 코드는 다음과 같습니다.

<&#63;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 );  
&#63;>

이 기사가 모든 사람의 PHP 프로그래밍 설계에 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.