Current Location: Home> Function Categories> mysql_list_dbs

mysql_list_dbs

Lists all databases in the MySQL server.
Name:mysql_list_dbs
Category:Uncategorized
Programming Language:php
One-line Description:Get a list of all databases in the current database connection

Function name: mysql_list_dbs()

Function Applicable Version: PHP 5.5.0 - PHP 5.6.x

Function usage: The mysql_list_dbs() function is used to get a list of all databases in the current database connection.

Syntax: resource mysql_list_dbs ( [resource $link_identifier = NULL] )

Parameters: $link_identifier (optional): MySQL connection identifier. If not provided, the last open database connection is used by default.

Return value: On success, return a MySQL result resource containing all database lists in the current database connection; on failure, return FALSE.

Example:

<?php // 创建数据库连接 $link = mysql_connect('localhost', 'username', 'password'); // 检查连接是否成功 if (!$link) { die('数据库连接失败: ' . mysql_error()); } // 获取数据库列表 $result = mysql_list_dbs($link); // 检查结果是否为空 if (!$result) { die('无法获取数据库列表: ' . mysql_error()); } // 打印数据库列表 while ($row = mysql_fetch_object($result)) { echo $row---> Database . "\n"; } // Release the result resource mysql_free_result($result); // Close the database connection mysql_close($link); ?>

Notes:

  1. The mysql_list_dbs() function has been deprecated and is not recommended for use in new PHP projects. It is recommended to use mysqli or PDO extensions to connect to and operate databases.
  2. Make sure that the database connection has been successfully established before using the mysql_list_dbs() function.
  3. For security reasons, it is recommended to use functions provided by mysqli or PDO extensions to connect and operate the database to avoid security issues such as SQL injection.
Similar Functions
Popular Articles