Why shouldn’t I use mysql_* functions in PHP?

I’ve seen this question so many times. There are many tutorials out there explaining why we should be using mysql_ functions in PHP. I remember a time in PHP, when this was the only way to interact with your MySQL databases.

As it turns out, just as things tend to do, PHP has evolved away from using this technique to interact with MySQL. They have even gone as far as deprecating all functions that have to do with mysql_ in PHP7. The replacement for mysql_ functions is actually mysqli_ (an improved version of the old mysql database connector).

MySQL vs MySQLi Comparison Cart

MySQL extension added in PHP version 2.0. and deprecated as of PHP 5.5.0.MySQLi extension added in PHP 5.5 and will work on MySQL 4.1.3 or above.
Does not support prepared statements.MySQLi supports prepared statements.
Extension directory: ext/mysql.Extension directory: ext/mysqli.
Transactions are handled by SQL queries only.MySQLi supports transactions through API.
MySQL extension lags in security and other special features, comparatively.MySQLi extension is with enhanced security and improved debugging.
MySQL extension does not support stored procedure.MySQLi supports store procedure.
MySQL provides the procedural interface.MySQLi provides both procedural and object-oriented interface.

If you application is using mysql_ for any functionality, it is highly recommended you stop using it and replace all of those function calls with mysqli_. By the way, mysqli_ is backwards compatible with mysql_. Meaning that you can simply do a quick find and replace on all of your code. Find “mysql_” and replace with “mysqli_”.

Leave a Reply