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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置