Opening a Connection and Selecting a Database : mysql_select_db « MySQL Database « PHP






Opening a Connection and Selecting a Database

 
<html>
<head>
<title>Opening a Connection to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "mydatabase";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
  die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db )
  or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
mysql_close( $link );
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.Create guestbook table
2.Using MySQL with PHP
3.mysql_select_db(): select database
4.mysql_select_db.php
5.mysql_select_db.php