PHP: Why you should no longer use the mysql_* functions
Plenty of PHP tutorials that explain how to connect to a MySQL database still use
functions such as mysql_connect() or mysql_query(). These come from the
ext/mysql extension and should no longer be used today.
They belong to an obsolete PHP extension (ext/mysql) that is no longer being
developed. PHP 5.5 (released in June 2013) officially marked the extension as
deprecated.
With PHP 7.0 (released in December 2015) the extension was
removed
for good. That also means that since
31 December 2018 there has been no officially
supported PHP version left that still ships ext/mysql.
Beyond that, the following technical reasons speak for one of the newer
extensions (ext/mysqli or ext/pdo_mysql). The old ext/mysql extension
supports none of the following:
- Prepared statements
- Parameterized queries
- Stored procedures
- Transactions
- An object-oriented interface
- Non-blocking, asynchronous queries
- Multiple statements
- Any functionality added since MySQL 5.1. That includes the new password authentication method, enabled by default since MySQL 5.6 and mandatory since MySQL 5.7.
The missing support for prepared statements in particular is a serious drawback. Among other things, prepared statements help you protect an application against attacks such as SQL injection.
A comparison of the two current extensions (ext/mysqli and ext/pdo_mysql)
can be found here.
About Netcup (advertisement)
The German host Netcup offers, among other things, affordable and powerful web hosting packages, KVM-based root servers and dedicated servers. With our voucher codes you can save even more (6€ off your first order, 30% off all KVM-based root servers, ...).