doupo2633 2011-10-02 20:43
浏览 93
已采纳

使用分离层(PHP和WordPress)与数据库交互

I quite often see in PHP, WordPress plugins specifically, that people write SQL directly in their plugins... The way I learnt things, everything should be handled in layers... So that if one day the requirements of a given layer change, I only have to worry about changing the layer that everything interfaces.

Right now I'm writing a layer to interface the database so that, if something ever changes in the way I interact with databases, all I have to do is change one layer, not X number of plugins I've created.

I feel as though this is something that other people may have come across in the past, and that my approach my be inefficient.

I'm writing classes such as

Table
Column
Row

That allow me to create database tables, columns, and rows using given objects with specific methods to handle all their functions:

$column = new \Namespace\Data\Column ( /* name, type, null/non-null, etc... */ );
$myTable = new \Namespace\Data\Table( /* name, column objects, and indexes */ );

\Namespace\TableModel.create($myTable);

My questions are...

Has someone else already written something to provide some separation between different layers?

If not, is my approach going to help at all in the long run or am I wasting my time; should I break down and hard-code the sql like everyone else?

If it is going to help writing this myself, is there any approach I could take to handle it more efficiently?

  • 写回答

2条回答 默认 最新

  • douluokuang7184 2011-10-02 20:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集