Hi everyone,
Is it possible to call for a function in the output of a MySQL DB
for example say this was the DB data -> '<td>' . function_call(). '</td>';
when i want to print out the Data using echo..
echo $row['data'];
it actually prints to the screen the function_call() as text and doesnt call for the function is there a way i can do this or am i missing something silly?
Thanks for any help
Alan
Calling for a php function when printing out the DB results
Moderator: General Moderators
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
Code: Select all
eval();- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Calling for a php function when printing out the DB resu
Neller wrote:Hi everyone,
Is it possible to call for a function in the output of a MySQL DB
for example say this was the DB data -> '<td>' . function_call(). '</td>';
when i want to print out the Data using echo..
echo $row['data'];
it actually prints to the screen the function_call() as text and doesnt call for the function is there a way i can do this or am i missing something silly?
Thanks for any help
Alan
I can't think of a single reason to store a PHP Function call in a database... Why are you trying to do this?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Possibly safer than eval() is to store the function name in the database without it's parentheses... i.e. it's name and nothing else.
Then call it like this:
If there are only a handful of functions you'd expect to be called then this should be easy to sanitize, but if you'r just blindly calling what the db says to call I'd be worried.
Then call it like this:
Code: Select all
while ($row = mysql_fetch_assoc($result))
{
$row['function_name'](); //This will call the function
}