Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Storing data of varying type.

    I am creating a flexible web application in PHP and am a little confused as to how to structure my database. I am trying to store what I am calling "data models" (since I don't know the correct technical term!) in a database which will describe what something is made up of, as well as the data for that object.

    For example:

    Code:
    Apple is made up of:
    - One Textfield
    - One Image
    - Two Booleans
    So in my database so far, I have two tables:

    Code:
    Data Models
    - id
    - name
    
    Data Model Fields
    - id
    - model_id (relation to the data models table above)
    - field_name
    - type (which I'd enter something like text field / image / boolean)
    These two tables map out my data model nicely, but now I need to store the actual physical data. So lets say I create a new Apple with the following data:

    Code:
    Apple
    - Test
    - image1.jpg
    - true
    - true
    I need to store that data in my database somehow. Obviously the immediate solution is to create a new table which relates to the fields table and store all the data in a column typed as text... but I am worried of the performance hit my application will take because of this. For example, storing a 0 or a boolean in a column typed text is way overkill!

    Can anyone help suggest a way in which I can structure my database to allow for a similar model based work flow?

    Thanks much!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,825
    Thanks
    78
    Thanked 4,413 Times in 4,378 Posts
    So how many different data models do you expect to have??

    The obvious answer, if you say "not too many", is to simply use CREATE TABLE to create a table exactly designed to hold an "Apple" object.

    If you say "thousands" then the problem is thornier.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •