Adsense 728 * 15

Search

Custom Search

PHP Database Connection



Connect to MySql Database in php


Connecting to MySql database in php you need three things. First one is hostname second one is username and last one is password.


mysql_connect() function is used in php for database connection.


Example-


<?php


$hostname='localhost';
$username='root';
$password='password';      //Enter your password


$connection = mysql_connect($hostname,$username,$password);


//Check whether you have connected successfully or not.


if (!$connection)
  {
  echo "Connection failed";
  }
else
  {
  echo "Connected Successfully";
  }
?>


mysql_close() function is used to close the connection.



<?php


$hostname='localhost';
$username='root';
$password='password';      //Enter your password


$connection = mysql_connect($hostname,$username,$password);


//Check whether you have connected successfully or not.


if (!$connection)
  {
  echo "Connection failed";
  }
else
  {
  echo "Connected Successfully";
  }


mysql_close($connection )
?>



No comments:

Post a Comment