/    Sign up×
Community /Pin to ProfileBookmark

Pull PHP code from MySQL database: eval()???

Hi guys,

I’m trying to make my site database driven.

I have the pages content in a mysql database on my server.

But when I pull the content from the database and print it – the php source from that content shows up in the page source, hence not actually parsing any php.

I found you had to use eval() to get the php to parse, however, I tried that (by changing print to eval) and all it did was give me an error saying [b]unexpected ‘<‘ in /path/to/file(12) eval()’d code line 1[/b] and got real confused.

Did some googling but didn’t really know how what I was looking for.

There is a way to do this right?

Cheers,
hamstar

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bokehFeb 21.2006 — Although it is possible to store code in MySQL it is wrong. Database storage should be resticted to content only. The whole reason you are having this problem is that your logic and content are mixed when really they should be completely separate. This is simalar to what has been preeched by W3C for ten years now about seperating content from layout.
Copy linkTweet thisAlerts:
@hamstarauthorFeb 21.2006 — um... I'm confused... could you rephrase that?
Copy linkTweet thisAlerts:
@Mester_PedizFeb 21.2006 — What he's saying is that you should not store the php code in the database along with the text, only text.

You should you the PHP and HTML to format the text you store in the database and then print it
Copy linkTweet thisAlerts:
@SpectreReturnsFeb 23.2006 — In some cases, it's probably more efficient to work with PHP from a database if you're developing a game in which near unique items run different PHP when they're used (I passionately hate PHP RPGs which store their items in php files, makes my used harddrive space like 5x bigger). In this case though, you'd want to keep only the minimum amount of data in the database.
Copy linkTweet thisAlerts:
@hamstarauthorFeb 26.2006 — eh? but then if I print the results to a database, and pull the page from the database, won't that negate using php for dynamicy?

Arse. PHP in databases was a good idea... wasn't it? why can't I do it?
Copy linkTweet thisAlerts:
@SpectreReturnsFeb 26.2006 — Just pull snippets of php from the database which can only be run in a certain context and thus don't deserve their own page.
×

Success!

Help @hamstar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...