PHP SQL Select Database

PHP SQL Select DB Statement Syntax

The syntax for the mysql_select_db statement is shown below. This statement will select the database that future queries will be sent to.

bool mysql_select_db ( string database_name [, resource link_identifier])

The value returned is true if there is success, and it is false if the command failed.

PHP SQL Select DB Statement Example

$dbname="mydata";  //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass) 
    or die("Connection Failure to Database");
echo "Connected to database server<br>";
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found." . $dbuser);
echo "Database " .  $database . " is selected";