dongmengan8620 2012-01-17 10:11
浏览 36
已采纳

用于映射许多MySQL表的PHP设计模式[关闭]

Ok, so I thought about implementing the Active Record Design Pattern for mapping a class over some tables in my MySQL database.

The thing is I want a generic class that will shuffle through my tables, doing basic CRUD transactions, based on what properties (fields from my db) are selected.

So I have methods for CRUD, which I want to select based on the properties passed to the object, properties which I access using __get and __set methods.

I thought about using an array, having it's keys as table prefixes and it's values another array containing the list of properties from each table.

But I think this is to complicated, cause I`ll have to shuffle thru a whole array to select the specified table.

Can you point me to some design tips I could use? Thanks!

  • 写回答

2条回答 默认 最新

  • dongshi1188 2012-01-17 10:51
    关注

    Use a pre-built library, like Doctrine, Propel or PHPActiveRecord that can generate your class files from the existing DB Schema. Also have a look at http://martinfowler.com/eaaCatalog/index.html for some ideas about the fundamental patterns used in Object Relational Mapping, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等