Selecting mySql Database

Selecting MySQL Database Using PHP Script

PHP provides function mysql_select_db to select a database. It returns TRUE on success or FALSE on failure.


bool mysql_select_db( db_name, connection );
Parameter Description
db_name Required – MySQL Database name to be selected
connection Optional – if not specified, then last opened connection by mysql_connect will be used.


Here is the example showing you how to select a database.

<title>Selecting MySQL Database</title>
$dbhost = 'localhost:80';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
  die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db( 'shiksha360' );

Admin has written 171 articles

Leave a Reply