Friday, 24 May 2013

How to create and connect to MySQL database

Creating a MySQL Database, Table :




How to connect to the database created above in the video :

PHP Code : 
<?php
$con=mysqli_connect("localhost","root","","demo_sf");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>


Code Explained :

mysqli_connect("server","username","password","database"); 
by default on localhost username = "root"  and password is ""

the if loop check whether the connection is made. If there is an error in the connect, it will display the error in the webpage [browser].

 

 

No comments:

Post a Comment