How to connect to database using PHP

Procedural style

Database Connection Using Php

$connection = mysqli_connect(“database-hostname”,”database-username”,”database-password”,”database name”);

//Error checking

if (!$connection) {
die(‘Connection Error: ‘ . mysqli_connect_error());
}

Where $connection is the link identifier .

For example if you are running the program on your local machine then hostname =”localhost’ ,username =”root” and password =”” .

If you are running the code on your development/live server then you can get the hostname from phpmyadmin and username and password from cpanel mysql database wizard.

Leave a Reply

Your email address will not be published.