PHP mysql_select_db() Function

Definition and Usage

The mysql_select_db() function sets the active MySQL database.

If successful, the function returns true. If failed, it returns false.

Syntax

mysql_select_db(database,connection)
Parameter Description
database Required. Specifies the database to be selected.
connection Optional. Specifies the MySQL connection. If not specified, the last connection is used.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db", $con);;
if (!$db_selected)
  {
  die("Can't use test_db: " . mysql_error());
  }
mysql_close($con);
?>