Sunday, November 20, 2011

How can you connect to MySQL from PHP?


Ans.  

Create a Connection to a MySQL Database
In PHP, this is done with the mysql_connect() function.
In the following example we store the connection in a variable ($con) for later use in the script. The "die" part will be executed if the connection fails:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
?>

No comments:

Post a Comment