How to connect mySQL using PHP?

Hy, I’m Kashif Nadeem and now i am going to explain you “How to connect mySQL database using PHP?

Try to under this simple connection string given below:

<?php 
$con = mysqli_connect("localhost", "root", "", "sublimegate");
if(!$con)
	echo "Database Connection Problem";
	else
	echo "Database Connection Successful";
?>

In above code you can see that PHP starting and ending tags are given and all mySQL connection Code is written inside these tags.

  • $con : is simple varibale in PHP that holds connections string.
  • mysqli_connect : is aspecial function used to make connection for mySQL. There are three or four parameters can be written inside it.
  • localhost : is your server name if you are using local server.
  • root : is a username that is created on local server to control and access mySQL database.
  • ” “: is a user password. Here blank show that by default root user has no password.
  • sublimegate : is your database name.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pageviews