How can I separate SQL from my PHP?

后端 未结 3 1073
[愿得一人]
[愿得一人] 2021-01-13 18:38

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 c

3条回答
  •  庸人自扰
    2021-01-13 19:12

    What I think you are looking for is a data access layer. I haven't read "Clean Code", but what I'm guessing Uncle Bob is getting at is to not have a bunch of raw SQL and database setup/access code all over the place. Abstract out the database prepare, execute, etc. code into a separate module and work from there.

    The comment about using stored procedures is also a good idea IMHO, though this is a highly debated topic with good points on both sides. I tend toward using SP's, but they aren't for everyone or every situation.

提交回复
热议问题