如何将 SQL 与 PHP 分开? [英] How can I separate SQL from my PHP?

查看:48
本文介绍了如何将 SQL 与 PHP 分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Clean Code 中关注 Bob 叔叔的建议,我想在我的 PHP 代码中没有 SQL.目前我正在使用准备好的语句并且我已经将我的数据库访问代码分解到模型类中.

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.

我最初的想法是将我的 SQL 分解成单独的 SQL 文件,然后在运行时加载它们.由于这涉及更多的磁盘 IO(我的直觉),我想知道是否有人建议以另一种方式进行操作.

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).

谢谢.

推荐答案

如果您只是想分离 SQL,为什么不使用存储过程?

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

这篇关于如何将 SQL 与 PHP 分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆