PHP MYSQL mysql_select_db – Select a MySQL Database

The mysql_select_db function is used to select a default MySQL database.

Syntax:

boolean mysql_select_db (string DatabaseName, resource MySQL_Handle);

Arguments:
DatabaseName
The DatabaseName is the name of a database on the MySQL server.
MySQL_Handle
The MySQL_Handle must be the handle of an open MySQL connection.

Return value:
If the selection is successful, the return value wil be a boolean true.
If the selection fails, the return value wil be a boolean false. This means that the named database does not exist on the server, or that the user does not have access rights to the database.

Example code:

<?php
$UserName = 'abc';
$Password = '1234';
$DbHandle = mysql_connect ('localhost', $UserName, $Password);
if (!$DbHandle) {
  die 'No database connection could be established.';
}
 
$DBName = 'w3db;
if (!mysql_select_db ($DBName, $DbHandle)) {
  die 'Database could not be selected.';
}
?>
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker