Organizational Research By

Surprising Reserch Topic

why are phps mysql functions deprecated

why are phps mysql functions deprecated  using -'Playing,Devil's,Advocate,a,little,here,as,I,stopped,using,these,functions,a,while,ago,,but,the,question,is,genuine,and,probably,matters,to,a,lot,of,SO,users.


asked Sep 30, 2015 by ashishshukla
edited Sep 30, 2015 by rajesh
0 votes

Related Hot Questions

2 Answers

0 votes

The mysql extension is ancient and has been around since PHP 2.0, released 15 years ago (!!); which is a decidedly different beast than the modern PHP which tries to shed the bad practices of its past. The mysql extension is a very raw, low-level connector to MySQL which lacks many convenience features and is thereby hard to apply correctly in a secure fashion; it's therefore bad for noobs. Many developers do not understand SQL injection and the mysql API is fragile enough to make it hard to prevent it, even if you're aware of it. It is full of global state (implicit connection passing for instance), which makes it easy to write code that is hard to maintain. Since it's old, it may be unreasonably hard to maintain at the PHP core level.

The mysqli extension is a lot newer and fixes all the above problems. PDO is also rather new and fixes all those problems too, plus more.

Due to these reasons* the mysql extension will be removed sometime in the future. It did its job in its heyday, rather badly, but it did it. Time has moved on, best practices have evolved, applications have gotten more complex and require a more modern API. mysql is being retired, live with it.

Given all this, there's no reason to keep using it except for inertia.

* These are my common sense summary reasons; for the whole official story, look here:

Choice quotes from that document follow:

The documentation team is discussing the database security situation, and educating users to move away from the commonly used ext/mysql extension is part of this.


Moving away from ext/mysql is not only about security but also about having access to all features of the MySQL database.


ext/mysql is hard to maintain code. It is not not getting new features. Keeping it up to date for working with new versions of libmysql or mysqlnd versions is work, we probably could spend that time better.

answered Sep 30, 2015 by amit_cmps
0 votes

Why are they deprecated?

Well, the fundamental reason is that the API was poorly designed. The mysqli library was created as a direct replacement for it, with better API design.

Yes, there are issues with the internal code for the library which means that it needs to be replaced, but if the API had been better designed in the first place, the mysqli library need not have been written; the improved code could simply have been swapped in to the existing library and we as developers could have carried on using the existing functions without needing to even know that things had changed internally.

However, that wasn't the case. The original API did have some critical design flaws which meant that when the PHP developers wanted to improve things, there were issues that meant that they could not do this.

Therefore, the best course of action for them was to provide a new API and deprecate the old one.

answered Sep 30, 2015 by rajnipancholi