I'm writing a CMS in PHP that allows the user to define different fields (e.g. a Blog page could have fields for Title (string), Content (rich text), Picture (file)). I need the user to be able to add and remove fields dynamically, and the only way I can think of to do it with relational DBs is to serialise all these values and store them in one cell.
我正在用PHP编写CMS,允许用户定义不同的字段(例如,博客页面可以包含标题(字符串),内容(富文本),图片(文件))字段。我需要用户能够动态添加和删除字段,我能想到用关系数据库执行此操作的唯一方法是序列化所有这些值并将它们存储在一个单元格中。
This seems like a slow approach and like I'm trying to fit something dynamic within a static structure. Could someone recommend anything that is PHP-compatible that would make this easier?
这似乎是一种缓慢的方法,就像我试图在静态结构中拟合动态一样。有人可以推荐任何兼容PHP的东西,这会让这更容易吗?
1 个解决方案
#1
4
One answer is document-oriented databases such as CouchDB.
一个答案是面向文档的数据库,如CouchDB。
Another answer is not to have a pre-defined database, but create it dynamically in response to user's wishes.
另一个答案是没有预先定义的数据库,而是动态创建它以响应用户的意愿。
Third possibility, within a relational database, is to have a table that looks like (id, name, value)
, so that a n-column row would be written as n rows in this table. It's not too pretty though. It is easy enough to find any specific value then, but if you want them all you will want a n-fold custom-built join :)
在关系数据库中,第三种可能性是具有一个看起来像(id,name,value)的表,以便在该表中将n列行写为n行。虽然它不是太漂亮。然后很容易找到任何特定的值,但如果你想要它们,你将需要一个n倍的定制连接:)
#1
4
One answer is document-oriented databases such as CouchDB.
一个答案是面向文档的数据库,如CouchDB。
Another answer is not to have a pre-defined database, but create it dynamically in response to user's wishes.
另一个答案是没有预先定义的数据库,而是动态创建它以响应用户的意愿。
Third possibility, within a relational database, is to have a table that looks like (id, name, value)
, so that a n-column row would be written as n rows in this table. It's not too pretty though. It is easy enough to find any specific value then, but if you want them all you will want a n-fold custom-built join :)
在关系数据库中,第三种可能性是具有一个看起来像(id,name,value)的表,以便在该表中将n列行写为n行。虽然它不是太漂亮。然后很容易找到任何特定的值,但如果你想要它们,你将需要一个n倍的定制连接:)