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_list_dbs() function in PHP


Tutorials »Php »

Topic

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




Explanation

This mysql_list_dbs() function fetches a list of the databases available on a MySQL server for a given connection and returns a result pointer containing the databases available from the current mysql connection.

Syntax

resource mysql_list_dbs ( [resource link_identifier])

Returns a result pointer containing the available databases on success, or FALSE on failure.

Example


<?php

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

//Returns result pointer containing available databases
$db_list = mysql_list_dbs($link);

//print each database returned by mysql_list_dbs function
while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
?>



Above code fetches list of database using mysql_list_dbs function on a MySQL server for a given connection $link. mysql_fetch_object function is used to fetch and display each database returned by the result pointer of mysql_list_dbs function.

RESULT:

database1
database2
database3...


See also: mysql_db_name().





Other Links

web hosting