logo

PHP mysqli database connection

mysqli

This article will help you connect mysql database with PHP using mysqli function, MySqli is Improved version of mysql function previously provided by PHP which is deprecated in new versions of PHP.

Lets start with database connection
we need 4 things to connect to database

  1. Host : which system/computer has datbase
  2. User : what is username to connect to database
  3. Password : what is password to connect to database
  4. Database : what is the name of database we are going to connect

Line#5 makes connection to database using provided credentials, if connected then then “if” block will not be executed, while it got some error then error no and error message will be displayed and further execution will be stopped with “exit()” function.

Now fetch some data from database.

let say we have jobs table and we want to get all jobs with status=1 and last_date is > current date

Comments