5

Possible Duplicate:
Advantages Of MySQLi over MySQL

I am building a large database and wondered which is the best to use?

I am sanitizing my values now and escaping characters for security but I would like to know the different benefits of these mysql querys in php?

Thanks.

Community
  • 1
  • 1
Basic
  • 1,818
  • 5
  • 21
  • 31
  • 2
    It took less than a minute to find three duplicates in http://stackoverflow.com/search?q=[php]+mysql+mysqli. Use the search function before asking questions. – Gordon Apr 12 '11 at 21:43

5 Answers5

14

Use MySQLi over the older MySQL functions. The "i" stands for "improved". The list of improvements can be found in the docs.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • I have written a user creation, verification, and login with normal mysql functions, is it that much of a benefit to change it security wise? – Basic Apr 12 '11 at 21:21
  • the main improvement would be the fact it's OOP as well, @Basic, it may be enough but you would be living in the past my friend, you need to stay up to date with the latest libraries to be able to take full advantages of the latest features as well as critical updates. – RobertPitt Apr 12 '11 at 21:22
  • 1
    The older `mysql_*` functions may wind up deprecated, too. – ceejayoz Apr 13 '11 at 00:03
2

Why not use PDO instead? You have the benefit of prepared statements amongst other features there and it would prove to be a wise decision should you decide to move to another DB one day.

http://php.net/manual/en/book.pdo.php

If you insist on using one of the options mentioned above, MySQLi is basically a more Object Oriented approach to the standard mysql extension. For the most part, they are functionality-wise the same. If you're building an OOP based application, MySQLi would probably be a wiser, more consistent choice.

Lior Cohen
  • 8,985
  • 2
  • 29
  • 27
2

First of all, you better use PDO (as Lior suggested) or an intermediate layer (coded by you) between your code and the database functions provided by PHP, so that you can easily change mysql with mysqli or whatever your like without re-editing your whole code.

As of the differences, mysqli has more functionalities (there are a bunch of new functions) and is also object-oriented.

gd1
  • 11,300
  • 7
  • 49
  • 88
1

From my point of view, the main difference (improvement) is that mysqli lets you execute multiple queries; that in turn allows you to execute (and retrieve results from) stored procedures with out parameters or which return resultset.

I do agree with others that using PDO is a better choice though.

a1ex07
  • 36,826
  • 12
  • 90
  • 103
0

For all those saying to use PDO. Is it only for the prepared statements? Because you can do prepared statements in mySQLi without PDO. Just FYI.

Brad Sparks
  • 488
  • 4
  • 9
  • 2
    Yeah, but have you ever tried to use them in production? They're a usability nightmare. PDO's interface is just *better*. – Charles Apr 12 '11 at 21:41