Function name: mysql_db_name()
Function Description: This function is used to obtain the database name of the specified database connection resource.
Usage: string mysql_db_name ( resource $link_identifier )
parameter:
- $link_identifier: Optional parameter, indicating the database connection resource identifier. If this parameter is not provided, the most recently opened database connection is used by default.
Return value: Returns the database name of the string type, and returns false if an error occurs.
Example:
- Use the default database connection to get the database name:
$link = mysql_connect("localhost", "username", "password"); $dbname = mysql_db_name(); echo "当前数据库名称:".$dbname;
- Use the specified database connection to get the database name:
$link = mysql_connect("localhost", "username", "password"); $dbname = mysql_db_name($link); echo "当前数据库名称:".$dbname;
Notes:
- This function has been deprecated in PHP 5.5.0 and has been removed in PHP 7.0.0. It is recommended to use mysqli or PDO extension instead of mysql function.
- Before using this function, you must first establish a database connection through the mysql_connect() function or other means of connecting to the database.
- If the $link_identifier parameter is not specified, the most recent database connection is used by default.
- If the function executes successfully, the database name of the string type is returned; if the execution fails, false is returned.
- Since this function was removed in PHP version 7.0.0, it is recommended to migrate to mysqli or PDO extension as soon as possible to achieve the same functionality.