15

Can someone clarify for me what the advantages and disadvantages of using MySQLi instead of MySQL? Are there situations where I should not use MySQLi? Do I need to configure my server differently in order to use MySQLi? For instance, do I need to upgrade Apache or PHP so I can support MySQLi?

3

5 Answers 5

36

Reasons why you should use MySQLi extension instead of the MySQL extension are many:

  1. MySQLi gives you prepared statements - a safer way of sending data to MySQL and protecting you from SQL injection. This alone should be enough for always choosing MySQLi over MySQL.
  2. MySQLi enables most of the MySQL features.
  3. MySQLi is object orientated.
  4. MySQLi supports prepared statements, transactions and multiple statements.
  5. The old MySQL extension is deprecated as of PHP 5.5.0

And there are other benefits. But mainly, you should focus on security and stabiltity - and MySQLi gives you just that.

1
  • 8
    I wouldn't call prepared statements "safer". easier to keep safe I'd say. Jan 17, 2012 at 8:28
8

PHP team refuse to support mysql extension any further. This reason is alone enough.

All other reasons don't make much sense:

  • MySQLi gives you prepared statements - one can use old mysql with manually handled plaeholders and get even safer. This alone should be stopping MySQL from useless deprecation.
  • MySQLi enables most of the MySQL features which most of PHP users never ever heard of.
  • MySQLi is object oriented - a pair of straight hands can make old mysql objec oriented in a matter of several hours.
  • *MySQLi supports

So, there are no advantages at all.
If you want to get along with non-deprecated but usable extension - go for the PDO.

1
  • 5
    your points are really stupid - sorry. why on earth would i spend several hours making an object out of something when there's already an object available? saying most people haven't heard of many mysql features is ridiculous and isn't even worth arguing because it makes no sense (completely subjective as well). also, i need multiple statements frequently. just because you don't know how to use mysql doesn't mean other people don't know either.
    – Anthony
    May 23, 2013 at 17:32
4

If you are using mysql > 4.1.3. Mysqli is a new interface for mysql in php. A quote from http://www.php.net/manual/en/mysqli.overview.php

What is PHP's MySQL Extension?

This is the original extension designed to allow you to develop PHP applications that interact with a MySQL database. The mysql extension provides a procedural interface and is intended for use only with MySQL versions older than 4.1.3. This extension can be used with versions of MySQL 4.1.3 or newer, but not all of the latest MySQL server features will be available.

Note:

If you are using MySQL versions 4.1.3 or later it is strongly recommended that you 
use the mysqli extension instead.
2

Always, if possible.

It is possible that MySQLi is not supported by your PHP install. However, most hosting providers have support for MySQLi.

0

Unless you are using an old version of the MySQL database (prior to 4.1.3) or require some functionality not yet included in MySQLi (I think there are one of two functions that weren't moved over) then stick with MySQLi when ever you can.

2
  • They are on our servers which we keep up to date. It all depends on your configuration and version of MySQL. Unfortunately I don't have any to hand and all the bench mark tests that come up in google are several years old running on older software and hardware.
    – Altrozero
    Jan 17, 2012 at 8:33
  • Probably not but when doing background processes and management picking the right function can save minutes of processing time. Especially when dealing with several million entries in a database. Realistically your probably not going to be doing that size of query via PHP.
    – Altrozero
    Jan 17, 2012 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.