Connect to MySQL Database Server

Started by VelMurugan, Dec 16, 2008, 09:43 PM

Previous topic - Next topic

VelMurugan

Connect to MySQL Database Server

To work with the MySQL database, we first need to connect to MySQL Database Server. PHP provides mysql_connect() function to do this, and requires three strings as input: 'hostname', 'username' and 'password'. Use Code-1 to connect to MySQL Database Server.

Code 1: test.php
<html>
<head>
  <title>Server test Page </title>
</head>
<body>
  <p>Testing
working of MySQL.</p>
  <?php
   
/* Connecting to MySQL */
   
$link mysql_connect("mysql_host""mysql_user""mysql_password") or die("Could not connect : " mysql_error());
   print 
"Connected successfully";
  
?>

</body>
</html>


If your script has no error, then Code-1 gives output as:

QuoteOutput 1: test.php
Testing working of MySQL.
Connected successfully

Source : Techxcel