
mysql_list_dbs 함수는 MySQL 데이터베이스의 목록을 반환하는 함수입니다. 함수의 반환값은 MySQL 데이터베이스의 이름을 포함하는 배열입니다.
mysql_list_dbs 함수를 사용하여 데이터베이스 목록을 얻는 예시 코드는 다음과 같습니다.
#hostingforum.kr
php
<?php
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$dbname = 'your_database';
$connection = mysql_connect($host, $username, $password);
if (!$connection) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
$result = mysql_list_dbs($connection);
while ($row = mysql_fetch_array($result)) {
echo $row[0] . "n";
}
mysql_close($connection);
?>
위 코드는 MySQL 데이터베이스의 목록을 가져와 각 데이터베이스 이름을 출력합니다.
mysql_list_dbs 함수는 MySQL 4.1.2 이상에서 사용할 수 있습니다. MySQL 5.0 이상에서는 mysql_list_dbs 함수 대신 SHOW DATABASES 명령어를 사용하는 것이 좋습니다.
#hostingforum.kr
php
<?php
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$dbname = 'your_database';
$connection = mysql_connect($host, $username, $password);
if (!$connection) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
$result = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_array($result)) {
echo $row[0] . "n";
}
mysql_close($connection);
?>
위 코드는 SHOW DATABASES 명령어를 사용하여 MySQL 데이터베이스의 목록을 가져와 각 데이터베이스 이름을 출력합니다.
mysql_list_dbs 함수는 deprecated 상태이므로, SHOW DATABASES 명령어를 사용하는 것이 좋습니다.
2025-05-11 07:05