PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_db_name Function in PHP


Tutorials »Php »

Topic

What is mysql_db_name() function in PHP?
How does mysql_db_name works?




Explanation

mysql_db_name() function retrieve the database name from a call to mysql_list_dbs().

Syntax

string mysql_db_name ( resource result, int row [, mixed field])

Returns the database name on success, and FALSE on failure.

mysql_db_name() takes the result pointer from a call to mysql_list_dbs() as its first parameter and the second parameter 'row' is an index of the result set.

By using mysql_list_dbs() function we can get the list of database name exist in the server as a result set, by using a pointer to this result set we can get the list of all the database names.

Example:


<?php
// Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

//retrieve list of existing database in the server
$db_list = mysql_list_dbs($link);
$i = 0;

//count the number of database in the list
$cnt = mysql_num_rows($db_list);
while ($i < $cnt) {

//display database name
echo mysql_db_name($db_list, $i) . "\n";
$i++;
}

?>


In the above code list of available databases in the server is fetched as a resultset. This resultset and index is passed as a parameter to mysql_db_name function to retrieve the database name of passed index. Index ranges from '0' to the end of the resultset returned by mysql_list_dbs() function.





Other Links

web hosting