Link to home
Start Free TrialLog in
Avatar of AphX
AphX

asked on

mysqli vs mysql?

I'm reading a PHP book. He is using mysqli_query etc.

Why is that?

I'm using mysql_query. Should I stick to it?
ASKER CERTIFIED SOLUTION
Avatar of Naveed_Manzoor
Naveed_Manzoor
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The "i" in mysqli stands for "improved". mysqli is a newer implementation of the mysql client library in php.

mysqli have some features not available in the standard php "mysql" client library. Most notably, it is object oriented and supports prepared statements. Using prepared statements is more secure.

Most tutorials and php/mysql scripts you find on the net will be using the older mysql_* functions. This is one reason to stick with this.

Except for the improvements in mysqli, the two library implementations are quite similar. Most of the old mysql_ functions also exists as a mysqli_ function. Learning to use one of these will to some degree also teach you to use the other.

My advice: learn both. Focus on mysqli, but experiment with the classic mysql_ functions also, so that you know how to use it and how to modify old code you might come across.
Avatar of Opalelement
Opalelement

MySQLi requires an additional PHP extension.

The only differences I know of are that MySQLi has multi_query, you have to give the link resource in each query, and it escapes strings for you.

I have read in many different places that MySQLi is faster, but the test results I see point to MySQL.