开发者

Whats the best way to allow users to create tabels in your db with php and mysql?

开发者 https://www.devze.com 2023-04-12 03:02 出处:网络
I have a page on my site that al开发者_开发百科lows users to create a custom form, e.g. they can edit the name of the input field so that it can hold any value that they name it with.

I have a page on my site that al开发者_开发百科lows users to create a custom form, e.g. they can edit the name of the input field so that it can hold any value that they name it with.

By doing so they create a new table in the database with the name of the input field as the name of the column

By doing so I am going to end up with a huge database, is there a different way of doing this?

I am sorry if my question sounds ridiculous but I am self-taught in MySql.


I would save the input fields in one table with an id linking to a form. The form will be save in an other table with an id.

Form:   
- 1 | Test  

Input:  
- 1 | Name
- 1 | SomeThing  

You can always find the input field by searching in INPUT where formId = $form['id'].


Whats the best way to allow users to create tabels in your db with php and mysql?

The best way is for sure: never allow that.

For the such a vague question I see the only not-so-ugly solution: one XML file per form.


Well, you can create a table "page" that can contain Form id as field. Another table will be "form" table, that will have all attributes of form and its "id"(primary key) will be used as "foreign"key in "page" table.
In this way, you can save extra table creation as well as can identify each form uniquely.


I would favour a noSQL database for this purpose, such as MongoDB, but as this isn't available, I would either go for MasterCassims solution or just use a TEXT field in mySQL to store serialized representations of the forms.

0

精彩评论

暂无评论...
验证码 换一张
取 消