How to use MySQLi_connect in PHP

As you all know that MySQLi is the updated PHP extension of MySQL.The MySQLi Extension is a relational database driver used in the PHP programming language to provide an interface with MySQL databases.MySQL is Deprecated in PHP 5.5 and will be removed in future.As we are have developed millions of App on PHP and MySQL.So in this tutorial i will tell you about how to use MySQLi connect in PHP to connect with your database.
Connect With MySQLi in PHP

MySQLi Connect in PHP

Let’s start connecting our database using mysqli in php.

MySQLi Syntax


Here is an example.(port and socket parameters are optional)

$con = mysqli_connect('localhost','username','password','database');

Here is an Example with Error handling.

$con = mysqli_connect('localhost','username','password','database');

// Check connection
if (mysqli_connect_errno()){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

Shubham Kumar

Hey, I am Shubham and i love Blogging, Coding and exploring new things and obviously sharing my experience with you.

Leave a Reply

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