Thursday, 7 January 2016

How to Create mysql Database Connection in PHP

Posted by
Connect MySQL database first create a connection with MySQL database .
Follow the steps for creating connection to MySQL database in PHP.

 1- creat a database in phpmyadmin .















2-  Define Username Password Server name and   take in variables.

$servername="localhost";
$username="root";
$password="";

3- use  mysql_connect() take three parameters server name ,username , password, connect to database.

4- use msql_select_db() function take two parameters one is database name , second is mysql_connect() infon in form of variable. Let see in coding example.

5- check the connection conformation.

Complete code for connect mysql database in php.

<?php
$servername="localhost";
$username="root";
$password="";
//connect to database this function
$conn=mysql_connect($servername,$username,$password) ;
// select the database 
$elect=mysql_select_db(example,$conn);
// this condition check connection conformations.
If($select)
{
echo "Connection is  Create a Successfully ";
}
else
{
echo "Connection is not create";
}
?> 





0 comments:

Post a Comment