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.

Syntax:

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.


Example:

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

<html>
<head>
<title>Selecting MySQL Database</title>
</head>
<body>
<?php
$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' );
mysql_close($conn);
?>
</body>
</html>

Admin has written 171 articles

Leave a Reply