mysql_select_db() Function
2.If no link identifier is specified, the last opened link is assumed.
3.mysql_select_db() function returns TRUE on success or FALSE on failure.
Syntax
bool mysql_select_db(database_name,connection)
Here, database_name specifies the database to select.
connection is optional. If not specified, the last connection opened by mysql_connect().
Example
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$con = mysql_connect("$hostname", "$username", "$password");
if(! $con )
{
die("Could not connect: " . mysql_error());
}
echo "Connected successfully";
// select current db
$db_selected = mysql_select_db("Aspell", $con);
if (!$db_selected) {
die ("Can\'t select : " . mysql_error());
}
mysql_close($con);
?>
$hostname = "localhost";
$username = "root";
$password = "";
$con = mysql_connect("$hostname", "$username", "$password");
if(! $con )
{
die("Could not connect: " . mysql_error());
}
echo "Connected successfully";
// select current db
$db_selected = mysql_select_db("Aspell", $con);
if (!$db_selected) {
die ("Can\'t select : " . mysql_error());
}
mysql_close($con);
?>
Output
Connected successfully
No comments:
Post a Comment