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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Programming within PHP

    Okay I fear Im going to have a hard time explaining my problem but here it goes

    I'm trying to create a dynamic system with the ability to be able to add custom fields to the database without creating new columns.

    Heres my stucture so far.

    tables | rows
    -----------------------------
    db_structure | fieldname
    db_data | fieldname, data

    * We can create a new field by adding a row to db_structure
    * Any data we wish to record is recorded to db_data.

    This is a very simplified description of what I am doing.

    I was wondering if there is a way of giving the end user the ability to program within the webpage by ultilizing these fields, I only need basic opperator and math functions but I think its important I give the user a 'textfield' so they can write actual syntax.

    Let me know your thoughts, maybe I'm trying to push PHP too far but i'm thinking I could somehow parse their input and perform operations based on that?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You are not pushing it too far at all. This is the correct way SQL wise to develop unknown fields available. Such thing would be used to write something like custom profile fields for your users to write in. You may need/want to provide additional information such as the datatype allowed, validation rules such as length, and so forth too which will help when accepting data to input.

    As for evaluation, that is more tricky. You can either write a parser of your own to scan in data (look and using the sscanf function for this) which is my recommendation, or if its valid PHP code you can use the eval function. Eval is spelled wrong, it should really be evil . All kidding aside, eval is a very dangerous function to run without a great deal of control (plus eval must be valid PHP code), since it will arbitrarily execute any code provided to it. On the other hand, writing a parser is a great deal of work, especially if you want to add more complex mathematics and taking into account precedence. Both procedural and OO will prove this to be a somewhat difficult task.

  • Users who have thanked Fou-Lu for this post:

    amof (11-15-2011)

  • #3
    New Coder
    Join Date
    Feb 2011
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for your response Fou-Lu, you've definately helped me alot here and sent me in the right direction.

    I think my best option is to provide some basic syntax, operators and custom functions and then parse the users input to generate valid php code. I really don't want to give them the ability of excuting raw php.

    Thanks once again!

    Quote Originally Posted by Fou-Lu View Post
    You are not pushing it too far at all. This is the correct way SQL wise to develop unknown fields available. Such thing would be used to write something like custom profile fields for your users to write in. You may need/want to provide additional information such as the datatype allowed, validation rules such as length, and so forth too which will help when accepting data to input.

    As for evaluation, that is more tricky. You can either write a parser of your own to scan in data (look and using the sscanf function for this) which is my recommendation, or if its valid PHP code you can use the eval function. Eval is spelled wrong, it should really be evil . All kidding aside, eval is a very dangerous function to run without a great deal of control (plus eval must be valid PHP code), since it will arbitrarily execute any code provided to it. On the other hand, writing a parser is a great deal of work, especially if you want to add more complex mathematics and taking into account precedence. Both procedural and OO will prove this to be a somewhat difficult task.


  •  

    Posting Permissions

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