How to connect MySQL database with php

Mahabubur Rahman
1
Before we planing a dynamic php project with mysql database, we must know how to establish  connect mysql database with php. MySQL query is very easy, so when we create simple php dynamic website we use MySQL database. So in this topics we try to know how to establish connect MySQL with PHP.

Let's get started. The first of all we find what php function use to connection establish. The mysql connection function of php is mysql_connect. We can use this function as following
<?php
       # FileName="config.php"
$hostname = "localhost";
$database = "test_database";
$username = "root";
$password = "root";
$connect = mysql_connect($hostname, $username, $password)
or die('Could not connect: ' . mysql_error());
//Select The database
$bool = mysql_select_db($database, $connect);
if ($bool === False){
  print "can't find $database";
}
?>
The above connection file is the most easy way to connect mysql database with php project.

After completing query close database connection as below.
<?php mysql_close($connect);?>

Tags

Post a Comment

1Comments
Post a Comment