Wednesday, 11 July 2018

What is MySQLi? What does it do?

What is MySQLi? What does it do?


MySQLi database system is relaible for both small and large applications.
MySQLi is open source relational database management system which is used on web.
MySQL must not be used in new development anymore.
Old extension does not support Prepared Statements and improved version of MySQL (MySQLi) and PDO that support Prepared Statements are object oriented.
For security reasons, you must use Prepared Statements. Its very important for your web application security.
By using Prepared Statements, you can protect your application from SQL injection.
MySQLi support for multiple statements and enhance debugging capabilities.
For MySQLi installation, click here : http://php.net/manual/en/mysqli.installation.php
You can connect your application to database by two ways :
  • Connection with the object oriented way
  • Connection with the procedural way
Connection with the object oriented way
I always recommend to open database connection by using object oriented way because it is very faster, secure and efficient.
  1. $db = new mysqli('host', 'user', 'password', 'database');
  2. if($db->connect_errno > 0){
  3. die('Error : ('. $db->connect_errno .') '. $db->connect_error);
  4. }
Connection with the procedural way
It is helpful for those user who want to switch to MySQLi from old MySQL because it is much similar to MySQL.
  1. $db = mysqli_connect('host','user','password','database');
  2. // check connection
  3. if (mysqli_connect_errno()) {
  4. trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
  5. }

PHP MySqli Basic usage :

Now i will show you the basic usage of MySQLi, such as select, insert, update and delete records. I hope this list will help you in developing application .
  1. MySQLi Prepared Statements - Insert Value in database table
  2. Insert Multiple Value in database table
  3. PHP MySQLi prepared statement select multiple rows

0 comments:

Post a Comment