How to Connect Database With PHP

In this tutorial, I will explain simple and easy steps that will help you to create a database connection with MySql database with PHP applications. It is very easy to write a script in PHP to get connect with most of the popular open source database like MySql.



Below is the complete example of how to make a connection with MySql using the PHP code. In the below example change the DB_SERVER, DB_USERNAME, DB_PASSWORD, and DB_DATABASE as per your database credential.

#connect with database

After defining the database variables, use the below code to make a connection with the database.

#Select the database

Now use the below code to select your database to use in your PHP based application.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , , , ,