我正在使用 PDO 连接数据库并在编码中使用 OOP 方法
这是获取帖子和评论的方法
class MyWeb{
public function SelectStatus($user_id){
        try{
            $DBC = new DBConnector();
            $query = "SELECT * FROM users U, posts P where P.user_id_fk=U.user_id and U.user_id=:user_id_fk";
            $params = array(":user_id_fk"=>$user_id);
            $result = $DBC->SelectArray($query,$params);
            if($result){
                return $result;
            } else throw new Exception("Post not selected!");
        }catch(Exception $e){
            echo "Caught Exception: ".$e->getMessage();
            return null;
        }
    }
public function SelectComment($post_id){
        try{
            $DBC = new DBConnector();
            $query = "SELECT * FROM comments C, users U WHERE C.user_id_fk = U.user_id and C.post_id_fk = :post_id_fk";
            $params = array(":post_id_fk"=>$post_id);
            $result = $DBC->SelectArray($query,$params);
            if($result){
                return $result;
            } else throw new Exception("Comment not selected!");
        }catch(Exception $e){
            echo "Caught Exception: ".$e->getMessage();
            return null;
        }
    }
}
以及如何调用函数并显示帖子和评论
<?php
        $NewStatus = $session->SelectStatus($user_id);
        if(!empty($NewStatus)){
            foreach($NewStatus as $data){
                $username = $data->username;
                $post = $data->post;
                $post_id = $data->post_id;
                                echo "".$username." | ".$post."";
                               $NewComment = $session->SelectComment($post_id);
                if(!empty($NewComment)){
                    foreach($NewComment as $cdata){
                        echo $cdata->comment;
            }
        }
    }
}
?>
但遗憾的是,我总是收到错误 ->致命错误:第 14 行的 C:\xampp\htdocs\RIO\RIO\RAI\session_rai\includes\db.php 中的最大执行时间超过 30 秒
那么,这种情况有什么解决方案吗?谢谢。