How to use MySQLi_connect in PHP

The MySQLi extension was developed to take advantage of new features found in MySQL systems versions 4.1 and Above. MySQLi is also sometimes known as the MySQL improved extension.The MySQLi extension is included with PHP versions 5 and later.

If you are using MySQL versions 4.1.3 or later it is strongly recommended that you use this extension.

The MySQLi extension has a number of benefits, the key enhancements over the MySQL extension listed below

  • Object-oriented interface as well as this extension also provides a procedural interface
  • Support for Prepared Statements
  • Support for Multiple Statements
  • Support for Transactions
  • Enhanced debugging capabilities
  • Embedded server support

So Today I am going to Write About Connecting to MySQL Server using PHP’s MySQLi Extension.

mysqli_connect() function is used to connect to database,this function returns a link identifier On success, that you can use in other MySQLi functions. On failure, it will throw an error.

MySQLi connection with the object method

MySQLi connection with the procedural method

If your MySQL port is different from default one (3306), you need to give the port number as the fifth parameter.

MySQLi connection with the Port Number

mysqli_connect() throws an error at failure and mysqli_connect_error() stores the error in last call to mysqli_connect(). If there is no error, it returns NULL.

Connection error checking

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments Protection Status
Would love your thoughts, please comment.x