4 ms·
> I actually met a young aspiring web developer who still learned DB-access with mysql_* functions. I urged him to switch to a sane framework like Laravel. Oh b
by aikah 11y ago
> I actually met a young aspiring web developer who still learned DB-access with mysql_* functions. I urged him to switch to a sane framework like Laravel. Oh boy he was happy in a month and learned bunch of best practices quickly.
There is some middle ground good practice which is using PDO, or even better Doctrine/DBAL . I don't think Laravel's ORM is that good, and the Active Record Pattern is somehow controversial.
- sbarre 11y agoI spent a good while trying to integrate Doctrine into my projects, and in the end I found it bloated and overly verbose and went back to PDO. I am sure that it has valid use cases, but for a lot of straightforward PHP projects, it's complete overkill and adds more work than it saves (in my opinion of course). I agree with knowing PDO though, I would say that's required knowledge for any self-respecting PHP developer.
- porker 11y ago> I spent a good while trying to integrate Doctrine into my projects, and in the end I found it bloated and overly verbose and went back to PDO. Were you integrating Doctrine, or were you integrating Doctrine/DBAL, as the parent poster recommends? Doctrine/DBAL is a bunch of useful helpers around PDO which take out a lot of the repetitive coding (and let me delete many home-grown methods I'd created to 'help' PDO)
- datasage 11y agoDoctrine is great for keeping rails on developers of various skill levels in large projects. But it does come at a cost of overhead. Most of the time for simple crud operations it doesn't matter, as long as you handle proxy generation and caching correctly. It can add up when you try to write code working on datasets. In those cases, I bypass doctrine and go direct to SQL.
- pc86 11y ago> Active Record Pattern is somehow controversial. What is controversial about AR?
- jsjohnst 11y agoMainly how easy it is to have zero clue that you're doing something horrible (SQL performance wise). Not positive that's what parent meant, but that's my guess.
- trm42 11y agoAR works nicely for simple basic queries but everything more advanced should be done with custom queries. That helps a lot :)
- jsjohnst 11y agoThe issue is that the line between simple and advanced is blurry, especially for an inexperienced developer. Maybe someday we (Royal we of all software engineers who build tools other engineers use) will learn there's a limit to abstraction layers applicability and put hard breaks into the code when that happens. I guess one shouldn't complain, the more tools allow developers to shoot themselves in the foot and not feel the pain until the leg needs to be cut off, the more variety of positions that will be open for engineers who've been there done that.
- reefoctopus 11y agoSimple: CRUD operations Advanced: Everything else
- jsjohnst 11y agoSadly, it's not that cut and dry. Even what seems to be a simple CRUD retrieve operation to an inexperienced developer could be a very costly thing to do due to relationships between entities.
- porker 11y ago> What is controversial about AR? How it represents rows as objects. How it makes people think about them. How it conflates modelling the domain with database structure. https://www.google.co.uk/search?q=activerecord+vs+datamapper https://www.google.co.uk/search?q=activerecord+vs+datamapper
- trm42 11y agoWell anything is better than the old and original Mysql extension for PHP. If you Google "PHP MySQL tutorial", there's lots of tutorials teaching still about mysql_connect and mysql_query. AR is controversial but it is approachable. In addition, I figure, those old PHP tutorials (code like it's the 2003!) are giving bad example and beginners can't understand the difference or realize that mysql_query + bunch of procedural code per file * 10 can be bad thing. I should've been a bit more clearer. Laravel taught him bunch of generic best practices (like deployment procedures, GIT, OOP, MVC, etc) and using Laravel Query Builder and/or Eloquent makes the DB code more sane compared to mysql_query. Laravel isn't the only framework which could've done this but like AR, it's quite beginner friendly :)