Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Class 'database' not found - PHP

Tags:

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

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

problem.php

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

database.php

<?php
class database
{
    ...
}
?>
like image 618
SamB Avatar asked Jan 17 '11 19:01

SamB


2 Answers

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

do this:

echo realpath (dirname(__FILE__));

that will output something like

/var/www/html/myfilepath/

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

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

$filepath = realpath (dirname(__FILE__));

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

if it is somewhere else you can do

require_once($filepath."/../../path/to/somewhere/else/database.php");
like image 166
Zak Avatar answered Oct 29 '22 05:10

Zak


do you include the file?

 include "database.php"; // or the path relative to database.php
 class problem
{

nevermind. Maybe :the include (required) is not opening the file.

like image 25
magallanes Avatar answered Oct 29 '22 05:10

magallanes