PHP Code:
<html>
<header>
<title>Listing 12.2 Opening a connection and selecting a database</title>
</head>
<body>
<?php
$user = "myusername";
$pass = "mypassword";
$database = "myusername";
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
print "Successfully connected to server<p>"
mysql_select_db( $database )
or die ( "Coudln't open database" );
// or die ( "couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$database\"<p>";
mysql_close( $link );
?>
</body>
</html>
mysql_select_db( $database
Comment