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_select_db Function in PHP


Tutorials »Php »

Topic

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




Explanation

mysql_select_db() function sets the active MySQL database.

Syntax

bool mysql_select_db ( string database_name [, resource link_identifier])

mysql_select_db() attempts to select existing database on the server associated with the specified link identifier.

Returns TRUE on success, or FALSE on failure.

We can select database in mysql server by using mysql_select_db function. mysql_select_db() selects the current active database on the server that is associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to set a link as if mysql_connect() was called without arguments.

Example


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

// select current db
$db_selected = mysql_select_db('mydatabase', $link);
if (!$db_selected) {
die ('Can\'t select : ' . mysql_error());
}
?>


In this script, replace "mysql_host", "mysql_user" and "mysql_password" with your mySQL login and password supplied by the information which you set when you installed mySQL.

Function mysql_select_db("mydatabase",$link) will select existing database with the database name passed as an argument along with the specified link identifier.

See also:





Other Links

web hosting