13

What should we do with questions using deprecated mysql_* functions? Almost everyday some users post a question with PHP code using deprecated mysql_* functions: every time, someone in the comments must tell them to use PDO or mysqli_*.

Should we decide a standard comment to post when this happens? Should this be automatized (for example, a bot that leaves the comments every time it finds a mysql_ function)?

This reminds me on how we used to post http://whathaveyoutried.com to every question showing lack of effort. Now this is banned and I don't think it is still considered good practice to ask "what have you tried" to those that clearly haven't tried anything.

Is the behavior of posting the PDO/mysqli comment going to be considered bad too?

7
  • 2
    The PHP community has generally come up with a set of standardized responses. Of course nobody is obligated to use them, so long as they remain respectable, but many do (or so I've been told). I wouldn't imagine a bot would be productive though; the risk of false positives is too high.
    – Servy
    Commented May 8, 2014 at 19:16
  • 1
    Related: meta.stackexchange.com/questions/143379/… Commented May 8, 2014 at 19:17
  • Check out the PHP tag for suitable responses. I don't think this needs to be automated.
    – Robert Harvey Mod
    Commented May 8, 2014 at 19:32
  • yeah, I don't think that too but I though it would be correct to consider it and discuss it.
    – Saturnix
    Commented May 8, 2014 at 19:35
  • 18
    1. Create canonical question "How do I do X in PHP?" 2. Create canonical answer "Don't use PHP." 3. Close all PHP questions as dupulicate of this question.
    – user1228
    Commented May 8, 2014 at 19:39
  • I need to find a way to include the deprecation, SQL injection and error checking all into one comment that would fit. Commented Nov 4, 2014 at 13:34
  • 2
    Just answer the question ignoring the fact that it's bad practice, then leave a comment noting the bad practice with a link to more information. (if and only if the question doesn't already mention it)
    – Kevin B
    Commented Nov 18, 2014 at 16:01

2 Answers 2

11

I have also found myself having to post a 'stock' comment on answers where the mysql_* functions are used too.

Please, don't use mysql_* functions, They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and use PDO or MySQLi. This article will help you decide.

If you want to use this comment yourself, copy this Markdown:

Please, [don't use `mysql_*` functions](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide.

A couple of questions have started to appear where the deprecation / removal of the functions is starting to cause problems and I tempted to amend the comment with this -

Here is an example of the problems you'll encounter.

[Here is an example](https://stackoverflow.com/questions/26299564/php-version-upgraded-cannot-use-few-functions) of the problems you'll encounter.
7

Editing for clarity (lest anyone think I recommend not answering)

Beyond posting comments on these, one thing that I would strongly argue for is to no longer answer questions with deprecated code using the same methods. It would instead make sense to show the right way. Sure, answering questions to using the mysql_ extensions will technically work for the user, and may be in-line with the notion of "answer the question at hand," they run the danger of providing answers with only short-term value, especially since this code is deprecated and will soon disappear.

Also, as many users are comfortable with using code with which they are familiar, it can be difficult for many to make a transition. By answering code questions using the same outdated methods (even with the warnings) provides an unhealthy encouragement to continue along this path. The existence of a large number of posts on SO which will be found by people through search engines with bad code will unfortunately encourage bad habits to continue.

I would humbly suggest that when answering questions of this type, that only answers using either mysqli or PDO should be used. (The former may be easier to explain for problems at hand to users struggling with their old mysql_ extensions). This way, the quality of the answers on SO for these questions should gradually improve.

3
  • 1
    I would see answering with the non-deprecated approach to be more valuable than not answering at all...
    – Makoto
    Commented Apr 19, 2015 at 21:34
  • Absolutely. I would not say to not answer, I would actually encourage answering with this method. In fact many (of the better ones anyway) tutorial sites no longer show how to use the deprecated methods. SO should be at least as good as these
    – nomistic
    Commented Apr 19, 2015 at 21:37
  • 2
    "I would humbly suggest that when answering questions of this type, that only answers using either mysqli or PDO should be used." - With a "prepared statement" of course ;-) Yet, nobody should really do rewrites neither. Commented Mar 22, 2017 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .