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 php 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)
- php and mysql in the tags, and not c (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
orPDO
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: deprecated-mysql-php
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