Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between mysqli and mysql? [duplicate]

Tags:

php

mysql

mysqli

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.

like image 508
Basic Avatar asked Apr 12 '11 21:04

Basic


People also ask

What is the difference between MySQL and MySQLi?

Basically, MySQL is the old database driver, and MySQLi is the Improved driver. The "i" stands for "improved" so it is MySQL improved. MySQLi can be done procedural and object-oriented whereas MySQL can only be used procedurally. Mysqli also supports prepared statements which protect from SQL Injection.

Why we use MySQLi instead of MySQL?

Reasons why you should use MySQLi extension instead of the MySQL extension are many: 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. MySQLi enables most of the MySQL features.

Can I use MySQLi in MySQL?

Yes – MySQLi has support for prepared statements in the underlying MySQL database. This support is provided through prepare, bind_param and execute methods of the MySQLi connection object.


2 Answers

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

like image 163
ceejayoz Avatar answered Sep 22 '22 14:09

ceejayoz


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.

like image 31
gd1 Avatar answered Sep 25 '22 14:09

gd1