I have a bunch of beautiful OOP code but the functions have these monstrously huge SQL queries. In 2010, should we really still be writing our queries in-line or is there an abstraction, like MVC, for SQL queries in PHP?
Thank you for your insights.
Edit: I probably should have mentioned this here. But as a professional PHP engineer, you wouldn't believe how often I've come across ORMs done horribly and (even worse!) ORMs programmed correctly that perform absolutely terribly (esp. on many-to-many and many join queries). I'm very negatively biased towards ORMs, with the exception of a few simple ORMs, like Kohana.
I guess what I was looking for was a generic Dynamic SQL design pattern.
you can write your queries (select, insert, update, delete,...) in stored procedures and only call those stored procedures from within your php code instead of writing your queries in your php files.
a good resource for learning stored procedures in mysql is this book:
mysql stored procedure programming
I don't know about PHP, but you could use an ORM. Wikipedia has a nice list of ORM software.
You can look into using Doctrine ORM. Not sure if that is what you were asking for or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With