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.

3 thoughts on “How to connect mySQL using PHP?

  • August 1, 2019 at 12:16 pm
    Permalink

    Hello there, just became alert to your blog through Google, and found that it is truly informative. I am gonna watch out for brussels. I’ll be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

    Reply
  • August 10, 2019 at 11:12 pm
    Permalink

    Hi, Neat post. There is an issue with your website in web explorer, would test this¡K IE still is the market chief and a huge element of folks will pass over your great writing due to this problem.

    Reply

Leave a Reply

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