How can I separate SQL from my PHP?

Following Uncle Bob's call to Clear code , I would not want to have SQL in my PHP code. I am currently using prepared statements, and I have included the database access code in the model classes.

My initial thought is to split my SQL into separate SQL files and then load them at runtime. Since this is due to the large number of IO disks (my gut feeling), I wonder if anyone has any suggestions on this.

In addition, I am interested to know if anyone has tried this and what dividends (if it pays off).

Thank.

+2
source share
3 answers

SQL, ?

+7

, , PHP -, .

PHP - - , HTML-. , (, Java). API .

.

, , ORM , , # Java PHP, .

, () ( , , - ) SQL heredocs . SQL yoru- .

SQL file_get_contents(), ?

PHP. PHP , ( - ). .

+7

, , . " ", , , , - SQL- . , , .. .

Commenting on the use of stored procedures is also a good idea IMHO, although this is a very controversial topic with good points on both sides. I tend to use SP, but they are not for everyone and for any situation.

+4
source

All Articles