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.

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题