致命错误:找不到类“数据库"-PHP [英] Fatal error: Class 'database' not found - PHP

查看:143
本文介绍了致命错误:找不到类“数据库"-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用问题类时,出现以下错误:

When I attempt to use the problem class I get the following error:

Fatal error: Class 'database' not found in path/problem.php on line 25

我不明白为什么会出现此错误,在problem.php的顶部,我需要database.php.发生什么事了?

I don't understand why I got this error, at the top of problem.php I require database.php. What is happening?

problem.php

problem.php

<?php
require("common.php");
require("database.php");
...
?>

database.php

database.php

<?php
class database
{
    ...
}
?>

推荐答案

这可能是包含路径问题.为了解决这个问题,在您的problem.php文件中

this is probably an include path issue. In order to fix it, in your problem.php file

执行以下操作:

echo realpath (dirname(__FILE__));

将输出类似

/var/www/html/myfilepath/

/var/www/html/myfilepath/

您的文件problem.php将在该目录中.

your file, problem.php will be in that dir.

现在,如果database.php也位于该目录中,则可以执行此操作

now, if database.php is also in that dir, you can do this

$filepath = realpath (dirname(__FILE__));

require_once($filepath."/database.php");

如果可以在其他地方做

require_once($filepath."/../../path/to/somewhere/else/database.php");

这篇关于致命错误:找不到类“数据库"-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆