Jump to content

Possible to use/execute php codes in a mysql table?


slyte33

Recommended Posts

Is it possible to execute a php code inside of a mysql table then doing something like:

 

$query=$db->execute("select * from example");
$code = $query->fetchrow();

echo $code[php_codes];

 

The field

[php_codes] would contain something like:
<? echo "hello"; ?>

 

Thanks :)

Yes, You can use the command eval to do this very purpose. But I warn you, Make 100% sure that what goes into it is sanitized and safe. You don't want arbituary commands being shoved in there, that can be durastic.

Try this:

<?php
eval('
  $string = "this";
  echo $string . " - "; 
  echo strlen($string); 
');
?>

 

And you'll notice it'll parse that very PHP code. You can pull it out of the database and wrap it within eval(). Just note you don't need the tags, you should strip them out. Just the code is fine with the function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.