Tuesday, January 27, 2015

How to connect MySQL database with php

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
       # 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);?>


  1. This article covers how hiring dedicated PHP developers can help you grow your website with ease. PHP programming is a great solution to make your web development process simple, cost effective and efficient.



Copyright @ 2014 Tech Tutorial .