MySqli Tutorial:PHP MySqli Extension

PHP provides three api to connect mysql Database.

1. MySql
2. MySqli
3. PDO

Out of these three MySql extension is deprecated as of PHP 5.5.0, and will be removed in the future.

MYSQLI is an improved object oriented extension introduced in PHP 5.

Advantages of MySqli over MySql

1. Support Object Oriented interface.

2. Concept of prepared statements is introduced which prevents sql injection.

3. Improved over all performance as compared to mysql extension.

PDO Tutorial

MySqli Tutorial: PHP MySqli Extension

Let’s Connect MySql Database with MySqli extension.

Select Data Using MySqli

Let’s Select some data from emp table. MySqli Provides following fetch Modes.

1. fetch_object().
2. fetch_assoc().
3. fetch_array().

Here i am using fetch_object() to fetch records as an object.

Insert Using MySQLi

 

NOTE: If you are taking any user input and inserting into database it is advisable that you always validate them. Mysqli also provides real_escape_string method which escape special character in a string.

Take an example from user registration system, where user choose his/her username and password.

How to Prevent Application From sql Injection

Tools to Check Sql Injection Vulnerability

 

Recommended Books For PHP And MySql

 

PHP And MySql Books on Amazon

PHP And MySql Best Books on Flipkart

In next MySqli Tutorial, i’ll show how to use prepared statement in MySqli.

Tagged , , . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.