Jump to content

how can you use php from a db ?


ricky spires

Recommended Posts

Hello,

 

This is not something that im at a stage of putting to use but its on my mind.

 

Is it possible to put a pages code into a database and pull out pages dynamically ???

 

so for example. if this was in a database

 

id                = (int)              = 1

pageName    = (varchar 255) = home

code            =  (text)            = <?php echo "hello world"; ?>

 

 

how would i returning the code on a page ?

 

"hello world" is simple but would you pull more complex code?

 

i have seen examples of it working on social networks but have no idea how they do that.

for example on Facebook pages "static FBML Iframes" they alow people to put in there own html but not php.

 

anyway. just food for thought.

would love to know the answer.

 

thanks

rick

Link to comment
Share on other sites

The only way to accomplish that would be to use eval() which is always a bad idea. A better solution would be to save the page (with PHP code) as a normal php page. Then use the database to dynamically determine the page to load.

 

EDIT: maybe I misread your request. If you are just wanting people to be able to "save" code to be displayed as text, the htmlentities() are htmlspecialcharacters() is what you want. I thought you wanted to execute the code.

Link to comment
Share on other sites

no, your right.

 

i was thinking of executing the code.

 

i was thinking to use it in a template system. so the nav calls the page id from the database and execute the code for the page that is stored in the database.

 

i thought it might be a good way the build a site without having 100s of php files.

 

:shrug: never mind. just a thought i had  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.