It's not the first time... It has recurring for almost every MySQL question where the asker posting mysql query with mysql_* not mysqli_* as happening in this question.

My question is, is this really effective? Well, we were all a newbie at one point and there will be a time where we will change or move from that mysql_* even without people saying so. And the usage of mysql_* is not dangerous as the asker might be someone who is learning from an outdated source, meaning using mysql_* would help them understanding the code much faster.

Bobby learns MySQL from certain site (http://www.tizag.com/mysqlTutorial/mysqlsyntax.php).
Bobby, who knows nothing about PHP, uses mysql_* function as it was written on the webpage.

Now, what if you, as Bobby, are asked to learn with MySQLi? That would means you have to convert each query into mysqli_* (Yes, I know... It's just a matter of adding i ). But then the code can be very messy as there can be some parts which Bobby uses mysql and mysqli.

So far, my teaching techniques are let the student uses mysql until they are ready enough to know what mysql_* stands for and then let them know (which some of them knows by themself), that they can use PDO, mysqli, and stuffs

  • 4
    The user is handling a sharp knife and cutting towards himself. Nothing has to go wrong right now, but at some point it might. He is of course free to do so and can follow any advice to keep doing so, but a little instruction to turn the knife around and cut away from the body might go a long way. – Bart May 4 '13 at 6:34
  • 3
    It's the same as when I see someone using archaic HTML elements like center and frameset...it usually doesn't prevent me from answering, but I'd be doing them a disservice if I didn't throw up a big red flag. As active SO users, we see such advice all the time, but you'd be surprised how many people are unfamiliar with best practices. – Tim Medora May 4 '13 at 6:45
  • 2
    @TimMedora Don't forget the font tag :P – hjpotter92 May 4 '13 at 6:54
  • I believe transitioning from mysql to mysqli is just an inch move, which is very trivial, and IMO letting them learn on their php for starters language would be more effective rather than pushing them with something that they will ask if they just start, like 'What is the difference between mysql and mysqli?'. I'd be best to let them learn mysql and then in the time, they will learn what is mysqli and why they should use them, by themselves, which IMO is more effective rather than getting told again then he forgot and getting told again. – Willy Pt May 4 '13 at 6:58
  • 3
    @WillyPt: The point isn't just to move, it's to remove the risk of SQL injection and learn how to query properly. Check my answer, I've explained it there. – Madara's Ghost May 4 '13 at 7:00

Yes, it is more effective then you might think. Even I got to know about PDO from one of those comments. Which is one of the reason that I'm constantly posting those comments. :P

It is a good idea to let the students learn from any source they prefer but not all sources are up-to-date and hence, we can and should inform them about good practices.

  • Thanks. I'll try giving out the spirit on giving out good pratices – Willy Pt May 4 '13 at 6:52

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.

[**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ).

As the author of said comment, let me share my insight with you.

It is effective

I've been getting some really good feedback, where I see the same people turning up later with PDO in their code, and sometimes asking about how to move from one to the other. Besides, if I helped just one user, it's all worth it in my eyes.

mysql_* is dangerous

More than you think, it's easier for a noob to learn SQL injection prone code on mysql_* than it is to learn prepared statements on mysqli or PDO, we're showing them the other side. And the sooner the better.

No one asked you to actively move

Read the comment, Please, don't use mysql_* functions in new code. We don't ask you to move your current code, that would indeed be messy and not helpful, but from now on, we want you to try to use a better library.

We're seeking to improve

We were getting feedback from the regulars and mods that the comment is annoying, and we're always trying to improve it. If you have some alternative phrasing, feel free to start a meta post on it, or ping me in the PHP chat.

  • I always wanted to ask, why switch from bit.ly to j.mp? – hjpotter92 May 4 '13 at 6:55
  • @hjpotter92: There was a time where the comment just barely fit into the 600 character limit, so we had to shorten it in any way possible. j.mp is shorter than bit.ly by two characters, and that was significant given all the links we have :) – Madara's Ghost May 4 '13 at 6:56
  • 1
    hmm, I created a smaller text using this app (^_^) – hjpotter92 May 4 '13 at 6:59

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