Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I separate SQL from my PHP?

Following Uncle Bob's avice in Clean Code, I'd like to have no SQL in my PHP code. Presently I'm making use of Prepared Statements and I've factored my database access code into model classes.

My initial thought is to break out my SQL into separate SQL files and then load them at runtime. Since this involves more disk IO (my gut feeling), I'm wondering if anyone has suggestions on doing it another way.

Also, I'm interested to know if anyone's tried this and what dividends (if any it pays off).

Thank you.

like image 832
Allain Lalonde Avatar asked Nov 29 '22 19:11

Allain Lalonde


1 Answers

If you're simply looking to separate the SQL, why not use Stored Procedures?

like image 124
madcolor Avatar answered Dec 06 '22 17:12

madcolor