Hacker News new | ask | show | jobs
by tangue 2716 days ago
Nice job and well written. A nice addition would be how to use pdo. I'm appalled by the number of ressources I see online which are using the old mysql api.
6 comments

> I'm appalled by the number of ressources I see online which are using the old mysql api

Recently authored articles? We have an internet filled with 20 years of PHP tutorials, and unfortunately for beginners there's not an easy way to evaluate if something utilizes modern best practices or is an Experts Exchange post from 2001.

I find strange you can't down-vote a link on Google, it should exist and Google should take it into account specially for technical links (less so for opinions articles or anything political)
Everything is political. I wouldn't want people to downvote Mercurial links into oblivion.

Anyway, Google links are pretty much already ordered by popularity.

That's the problem, in technical links popularity (as in number of visits) is not linked to correctness, that's one of the reasons StackOverflow is so useful, because the top-voted answer is like 99% of the times the most correct (useful) one.
Except when that answer is 5 years old and is as wrong as the ExpertsExchange post from 2001.
Unlike EE, though, any user can propose an edit to that now-incorrect answer (or just edit it outright, if they have 2k rep).

A nice big "this answer is outdated, see [other answer]" note does wonders.

Built-in SEO gaming would be a weird feature
Yep, the plethora of out-of-date resources is what I'd place as the main issue with PHP today. I usually steer people to use the Laravel framework since it makes it difficult to write bad/dangerous code.
This is a very good resource for PDO: https://phpdelusions.net/pdo
https://phpdelusions.net/pdo has done a very thorough job of covering PDO IMO and makes a fantastic companion to https://phptherightway.com/.
PDO is definitely on the list. There are very few resources for it.
Can confirm. I've written one site with PDOs and a lot of sites with the old stuff. PDO is definitely a different feel to wrap around, and more resources on it would definitely be good.

For what it's worth though, my understanding is mysql_ functions are removed completely as of PHP 7. So that old documentation will just not work, rather than teaching people the least secure option of how to write their website.

You're right, but you can just replace mysql_* with mysqli_* if you're so inclined.
that doesn't work.

mysql_query($sql, $link);

mysqli_query($link, $sql);

I’ appalled that my 10 year old website recently suddenly broke because someone updated PHP to 7.2.

Then I realized it was pretty amazing that it lasted that long in the first place.

similar. got a call from someone re: a site built on a homegrown mvc framework from 2000/2001 (when PHP4 was just out).

this call came in late 2017 saying "hey, we migrated the site and it doesn't work". There was some change in PHP5.6 and the initial PHP4 code had some "by reference" class stuff that wasn't working any more. It was a small change to get it working again, but there was enough PHP4 in it that a move to PHP7 wasn't going to work without a lot of work. I'd suggested a rebuild, which... wasn't too well received. Pointing out that they'd had 16 years of functionality on a web codebase (with no other costs) was probably as much ROI/value as you'd ever be able to get out of anything.