这是来自User.php文件
<?php
class User {
public static function find_user_by_id($user_id) {
global $database;
$result_set = $database->query("SELECT * FROM users WHERE id=$userid");
$found_user = mysqli_fetch_array($result_set);
return $found_user;
}
}
?>
这是来自admin_content.php。在此页面中,我收到错误消息。
<?php
$found_user = User::find_user_by_id(2); // This is line 23
echo $found_user["username"];
?>
这是我遇到的错误。
致命错误:未捕获错误:在C:\ xampp \ htdocs \ gallery \ admin \ includes \ admin_content.php:23中找不到类'用户':堆栈跟踪:#0 C:\ xampp \ htdocs \ gallery \ admin \ index.php(24):include()#1 {main}在第23行的C:\ xampp \ htdocs \ gallery \ admin \ includes \ admin_content.php中抛出
答案 0 :(得分:6)
使用某种自动加载器或使用require / include函数
在admin_content.php中添加
include "User.php";
after <?php