Great posting of stupid things programmers do… The * stupidest things I’ve done in my programming job
In all honesty, I think most programmers should make these kinds of mistakes on their own, and then learn from them.
One that does not understand the wrong, cannot become better.
To extend the post, specifically for PHP:
1. ORM
One should use Doctrine, or propel. I personally favour Doctrine.
2. EAV
Doesn’t need to be PHP specific.
3. Database Access
PDO with Doctrine, can’t really go wrong…
4. IDE
Use an PHP IDE, there are lots out there now.
Eclipse PDT, NetBeans PHP, PHPEditor, Aptana… etc…
I currently favour NetBeans. I have tried Eclipse PDT, Aptana, NetBeans… and I’m currently using NetBeans, and loving it.
5. Transactions
Just use them. This reminds me to clean up, the data injector to use transactions. I know I can… I don’t know why I didn’t.
6. Prepared Statements
Prepared statements in PDO, or subsequently Doctrine, is trivial.
PDO example:
<?php
// the following statements has question marks inside the query...
// meaning, that those will be replaced with values later. Think of the command as a combination of sprintf, and mysql_real_escape_string, together... but smarter.
$query_string = 'select * from tableA where id = ? and column_a = ?';
$this->prepared_statement = $this->DBH->prepare($query_string);
$this->prepared_statement->execute(array(123, "some random value, but will auto quote everythign for me even if it has \" and ' inside the string"));
$results = $this->prepared_statement->fetch(); // or
$results2 = $this->prepared_statement->fetchAll();
Doctrine is an ORM, so if you’re using Doctrine, basically everything is prepared for you.
7. Business Logic
LOL, sorry… this one makes me laugh, as code at work has this type of “design” (or lack of) in legacy code. This legacy code is less than a year old. Thank you Botched Code!