38

This has been talked about quite a bit in the PHP chatroom, and this comment is used to direct people to the why should i stop using mysql_* functions? question.

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Gordon, Madara, Jack and others in the chat (with myself butting in) have been trying to work around two differing viewpoints and trying to find some kind of compromise between the above (which is very attention grabbing, as a block of text), and something a little more like this, as a one-liner (This was my suggestion; feel free to add your own):

Use of the mysql_* functions in PHP is discouraged in favor of PDO or MySQLi (find out why)

The negative sides of both of these is that the block of text is deemed too much, too spammy, too distracting, etc. The links are also shortened to allow for such a large comment, which can lead people to thinking they are dubious and reporting comments.

On the other hand, the one-liner doesn't seem to have enough impact; it can be dismissed too easily, and wont do much to make someone go clicking on links to find out why they should stop using something awful.

The point of these is that the tag is massively popular, and it is filled with beginners to PHP who have literally just waltzed out of their (yuck) w3schools tutorial, adamant that they are now experts in PHP (I would say this is a dramatization, but just watch the PHP tag for a day. Trust me; you'll either want to run and hide, or do something about it). In fact, the PHP chatroom has even made a browser extension for PHP close votes.

mysql_* functions are widespread in all of the tutorials at the top of Google's search hits, and also in many of StackOverflow's older answers.

Since these answers have sizable view counts, I'm making a request for (as well as the discussion on) doing something akin to what happens with duplicate posts: we add a header or footer to old posts that match a certain criteria and that stick the one-liner form of the deprecation notice into a block, for emphasis. That way the call-to-action is more effective, but not deemed as spammy. The best of both worlds. Sorta.

Does anyone else think this could be improved on in some way?

Criteria for a mysql_* blockquote edit (keep in mind this is entirely my opinion):

  • Question at least a year old (arbitrary)
  • and in the tags, and not (for the raw API questions, if any).
  • A match for mysql_connect, mysql_query, mysql_num_rows, mysql_fetch_assoc, etc
  • No matches for mysqli or PDO in the body of the question (for the "how do i do this in x" questions)
  • Significant number of views

While this is feasible, it's often not wise to do machine edits without assessing if anything will get changed for the worse. If anything, it's probably wiser to do this manually, since we already run around commenting the hell out of the new questions and persuading people to start using a user-friendly API.

Edit:
Do people think it's still OK to be editing a post to add blockquotes to the top, like how duplicate marking used to be before it was automated? Could the 10k mod tools include adding deprecation warnings to old content using summaries from a wiki system? e.g. something like this:

Wiki Summary:
Use of ext/mysql in PHP is strongly discouraged in favor of newer, safer, and more user-friendly APIs such as PDO or MySQLi, that support prepared statements, and will not be removed from PHP in the immediate future. This warning is here because this question has been answered, but due to the age of the post, it may no longer apply.

Chat transcripts (keep in mind we have fun in that room... cough, Zardoz):

https://chat.stackoverflow.com/transcript/message/8240228#8240228

https://chat.stackoverflow.com/transcript/message/8263447

Discussion on the GitHub gist we forked

16
  • 5
    Is this a feature request for automated posting message like that? If so: hell no! Bad things will happen.
    – PeeHaa
    Commented Mar 14, 2013 at 19:42
  • @PeeHaa well, if we could run around editing the big ones, I'm all for that
    – Amelia
    Commented Mar 14, 2013 at 19:43
  • 10
    I would favor a shorter "find out why" approach over the current standard comment. To me, the current one reads a little harshly. The "See the red box?" implies that the PHP n00b has in fact read but ignored the documentation, when we all know that most of the time they are not even aware that official docs exist, having gotten their info from collected tutorials. I'm not suggesting an alternative as I haven't come up with one yet, but I hope to see something proposed. Commented Mar 14, 2013 at 19:50
  • 2
    Oh dear, you've awakened casperOne now. Commented Mar 14, 2013 at 19:51
  • 5
    Likewise, the declarative format of Learn about prepared statements reads to me like GTFO AND LEARN ABOUT PREPARED STATEMENTS!. I would prefer less demanding language along the lines of Start reading about prepared statements instead, but it's longer... Again - I await a better proposal :) Commented Mar 14, 2013 at 19:53
  • 2
    Meh, automated editing is a total non-starter, but +1 for the effort.
    – Charles
    Commented Mar 14, 2013 at 19:58
  • 1
    @Hiroto Was this discussion today? Can you link to the chat transcript? Commented Mar 14, 2013 at 19:59
  • @meta.michael added them, and also the github gist (with comments and forks)
    – Amelia
    Commented Mar 14, 2013 at 20:04
  • I thought about creating a meta question about this too. The current box is much to spammy and I will never use it. I think you just need to have a question to link to and just write a comment each time. Doing this automatic is a no-go IMO
    – Wouter J
    Commented Mar 14, 2013 at 20:13
  • 1
    @Charles well, we are programmers. We're lazy and try to find more ways to kill time (read: playing games or looking at cats) while getting the same amount of work done. Unless we really like our jobs.
    – Amelia
    Commented Mar 14, 2013 at 22:03
  • What about those working on PHP4 systems? Suggesting PDO or mysqli will possibly confuse people more than anything. Commented May 9, 2013 at 15:27
  • 1
    @JamesDonnelly PHP4 systems are ancient, buggy, filled with holes, and you'd probably have an easier time showing your boss that the wasted time fixing these security holes could be spent on other tasks by simply upgrading and refactoring a bit. If code is in place that works, fair enough, but when refactoring it, upgrading at least parts should be a primary concern. The general consensus of the cv-ring is that PHP >= 5.3.0 is pretty much the only PHP that should be in use. anything lower is awful to use (in 5.2 to 5.3 alone, there were 140 security fixes)
    – Amelia
    Commented May 9, 2013 at 16:01
  • @Hiroto I don't disagree with that at all, however the PHP4 system I occasionally have to work on is almost entirely intranet and consists of well over 5,000 PHP scripts. Commented May 9, 2013 at 16:40
  • @JamesDonnelly youchy. However, if you're a junior being made to work on a legacy system fresh out of college, or if you have no experience with PHP4's insufficiencies, then it's far better to just admit this and work on something newer. If you need PHP4 mysql help, though, I usually say ask a pure SQL question, and then read the reference manual for ext/mysql several times. Painful (masochistic, even), but effective.
    – Amelia
    Commented May 9, 2013 at 16:44

5 Answers 5

18

High-impact version

Less rude, more friendly:

There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

Copy-pasta Markdown code:

There is **no more support** for `mysql_*` functions, they are [**officially deprecated**](https://wiki.php.net/rfc/mysql_deprecation), **no longer maintained** and will be [**removed**](http://php.net/manual/en/function.mysql-connect.php#warning) in the future. You should update your code with [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) to ensure the functionality of your project in the future.
2
  • "There is no more support.." is confusing as to who no longer offers support. PHP and/or StackOverflow.
    – James
    Commented Sep 2, 2013 at 1:14
  • 2
    In a nutshell: PHP doesn't and SO shouldn't.
    – CSᵠ
    Commented Sep 2, 2013 at 11:38
13

As the author of said comment, I can tell you this.

We've tried very hard to make the comment as informative as possible, while keeping a nice, polite language. I've gotten very good feedback from users who used it and learned. "Wow, didn't know that, thanks!" followed by questions about moving from mysql_* to PDO.

If you have an alternative wording/phrasing you'd like to propose, you can go to the PHP chat room and ping us (me) there. We'll discuss the finer points, and if accepted, I'll edit the comment and push it to the users who use it.

Our goal is, bottom line, to help users understand that what they are doing is wrong. If you have a better way, we'd love to hear it.

2
  • 1
    Hmm ... so you said you made it. Strange. That's not how I remember it.
    – tereško
    Commented Aug 13, 2013 at 13:56
  • @teresko: The current version was made by me, based on the previous version. The original version came from the PHP room. Commented Aug 13, 2013 at 15:01
8

In my opinion, the issue here is that the text is in a comment and not in an answer. As such, rewording and rehashing won't make any difference to the spam factor, which is (the way I see it) the real problem.

So my proposed solution - one that I have been implementing myself in a very slow and stop-start manner - is to answer questions where the asker has posted code that uses the mysql extension, answer them well, and include the comment's text prominently in the answer body. Couple of examples of what I mean:

I believe that this approach, in the long run, will have the best effect. You appear friendly to the asker because you are giving them a good answer, and because you gave them a good answer the answer is likely to collect upvotes, and as an added effect they are more likely to pay attention to what you say.

If you don't feel the question should be allowed to live for very long (questions that are duplicates, too localized, or off topic) you can always make your answer community wiki.

Now, I do accept that this is likely to require considerably more effort than the hit-and-run comment - but isn't that sort of the reason this debate started in the first place? Who knows, you might even help someone along the way (perish the thought).

6
  • +1 best approach! but note that user interest is diminishing the more one scrolls down the page and for a new user landing on the question from a search engine a comment warning about the use of ext/mysql is educative and pretty up top. IMHO this type of comment looks spammy only for regulars of SO, but it actually adds to the post and is relelated
    – CSᵠ
    Commented Apr 19, 2013 at 23:02
  • +1 Completely agree as answering the question helps people learn, but, potentially educate them too. We aren't helped by the fact that half the tutorials out there are full of mysql_*...
    – nickhar
    Commented Apr 19, 2013 at 23:03
  • 1
    I'm all for this, but i still think we shouldnt have link shorteners. the spamchecks could start flagging it :3
    – Amelia
    Commented Apr 20, 2013 at 1:25
  • 3
    @Hiroto in this scenario the short links are no longer required. The only reason they existed at all was to allow the comment to fit into a single post in chat (500 chars) - the post length limit in answers is considerably larger and this should no long be an issue. To that end, I have updated my fork of the Gist to contain only the expanded/long versions of the links.
    – DaveRandom
    Commented Apr 20, 2013 at 9:10
  • You still included a solution using mysql_*...downvote answers which include it and only give answers using mysqli_* or PDO. Don't be scared of the -1.
    – user7116
    Commented May 9, 2013 at 16:30
  • 1
    Including said comment (with its overflowing formatting) in answers to me usually looks like repwhoring (as it's an agreed on SO meme). If you want to include it, post it as comment below your answer. (I still believe answering trivial mysql_ duplicates won't entice people to investigate/switch just because the addendum says otherwise.)
    – mario
    Commented Aug 21, 2013 at 22:49
4

The "mysql_* is deprecated" comments have become extremely spammy. When a user is learning PHP for the first time or is just trying to wrap his head around a specific problem, interjections of "use PDO!" are simply off-topic. Some go so far as to say that the asker should drop everything, implement mysqli_*/PDO, and then come back.

Should we add "Use Chrome/Firefox" comments to every Internet Explorer question? Should we add "Use jQuery" to every Javascript question? Of course not! Then why do so many persist in hijacking unrelated posts to push mysqli_/PDO? When the users become concerned about security, they will ask. Until then, let's try to give them room to learn (and perhaps fail) at their own pace.

5
  • Point taken, and I will update my example. However, the larger point remains: Does it really make sense to develop a habit of injecting unrelated tips into every single post on this subject? Commented May 9, 2013 at 15:55
  • 2
    I think the comments are a part of education; often it's a revelation when a new user finds out the existence of named parameters, strong typing in queries, prepares, and the ease of use a decent OOP class can provide. However, spamming it literally everywhere is, well, spammy.
    – Amelia
    Commented May 9, 2013 at 16:03
  • 1
    Also "use jquery" is a common meme here. It solves all the problems.
    – Amelia
    Commented May 10, 2013 at 12:49
  • No. We should add "please learn javascript" to every bad jquery question.
    – tereško
    Commented Aug 13, 2013 at 13:54
  • 3
    Should we add "Use Chrome/Firefox" comments to every Internet Explorer question? Not a great analogy, as Internet Explorer is OK and is not deprecated, and those saying otherwise are doing so out of personal opinion / religious war, which is not what the mysql_* warnings are about. Commented Jan 25, 2014 at 5:31
1

I think to say "Please, don't use mysql_* functions in new code." is a little dictatorial. When I was learning php and mysql, I knew about MySQLi and PDO over mysql_*, but I still started by learning mysql_*, simply because there are more resources/tutorials/help available. So I think any comment should not tell the user what to do, but instead just informing them of the deprecation, so after they are confident in php and mysql_*, they can update themselves into using either MySQLi or PDO.

I also support the idea that these comments should only be posted along with the answer (and not automated). As David X. Random, this is much more friendly and prevent spam, and I think will also stop people posting the comment just to get upvotes, while not helping the asker in any way at all.

You must log in to answer this question.

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