Posted by Abdul Aziz on Tuesday, March 16, 2010
Opening a Connection and Selecting a Database from PHP/MySQL
<html>
<head>
<title>Opening a connection and selecting a database</title>
</head>
<body>
<?php
$user = "aziz";
$pass = "pakistan";
$db = "sample";
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
print "Successfully connected to server<P>";
mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<P>";
mysql_close( $link );
?>
</body>
</html>