2015-05-07 19:24
浏览 57


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

[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
       $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


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
    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']) )

    This will call the function login. You can also pass parameters if you want, as you would any other function.

    点赞 评论