从MySQL中调用PHP函数
I'm not even sure if this is possible, but essentially I want to have a function stored within my MySQL database, so here I have my database
Database->pages:
[id] [name ] [content ] [enabled] [main] [parent]
[6 ] [login] [login();] [1 ] [0 ] [5 ]
Now I'll have the set returned
public function viewPage() {
global $db;
$query = <<<SQL
SELECT content
FROM pages
WHERE id = :getid
SQL;
$resource = $db->sitedb->prepare( $query );
$resource->execute( array (
':getid' => $_GET['id'],
));
foreach($resource as $row){
echo $row['content'];
}
}
Last but not least I have my viewPage.php page that has
$static->viewPage();
So when I go to viewPage.php?id=6 I want it to pull the data and since content is login(); I want it to call the login(); function which would be translated into an include file. Is this even possible?
我甚至不确定这是否可行,但基本上我想在MySQL数据库中存储一个函数 ,所以这里我有我的数据库 p>
Database-&gt; pages:
[id] [name] [content] [enabled] [main] [parent]
[ 6] [登录] [登录();] [1] [0] [5]
code> pre>
现在我将设置返回 p> \ n
public function viewPage(){
global $ db;
$ query =&lt;&lt;&lt; SQL
SELECT content
FROM pages
WHERE id =:getid
SQL ;
$ resource = $ db-&gt; sitedb-&gt; prepare($ query);
$ resource-&gt; execute(array(
':getid'=&gt; $ _GET ['id'],\ n));
foreach($ resource as $ row){
echo $ row ['content'];
}
}
code> pre>
最后 但并非最不重要的是我的viewPage.php页面有 p>
$ static-&gt; viewPage();
code> pre>
所以当我去viewPage.php?id = 6我想要它来提取数据,因为内容是login(); 我希望它调用login(); 将被翻译成包含文件的函数。 这甚至可能吗? p>
div>
You can use variable functions to achieve this effect. We would need to verify that the function is_callable
beforehand.
Let's say we get a row back with the field name
set to login
. You can do this:
if( is_callable($row['name']) )
$row['name']();
This will call the function login
. You can also pass parameters if you want, as you would any other function.