douya7282 2015-05-07 19:24
浏览 76
已采纳

从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?

  • 写回答

1条回答 默认 最新

  • douzi2785 2015-05-07 19:32
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services