Php connect to mysql database

Create a new page and save as conn.php and paste the below stated code


<?php

function conectDB() {
$host = "localhost";
$username = "root";
$password = "";
$db = "Write your database name"; // Write your database name here
$connect = mysql_connect($host,$username,$password);
if(!$connect){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Write your database name") or die('Could not connect: ');
}
?>
 
Then we can include the conn.php on every pages that connects to mysql database

<?php
include "conn.php";
$dbHandle = conectDB();
?>

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...