You are using a relative path and, depending on the string of requires
e includes
that you have defined, what is two directories above DAO/usuario.php
is not two directories above the initial script.
Let's say you have it that way
- index.php
- otro directorio
- otro_script.php
- DAO
- usuario.php
It would be understood that compra.php
is in the same directory as index.php
, but it turns out that usuario.php
is running at compile time along with index.php
, so you're calling a file two directories above index.php
and that clearly does not exist.
What I always recommend is to keep a single point of entry to the application (index.php) where a constant that sets the root directory is defined:
index.php
<?php
define('HOMEDIR',__DIR__);
require(HOMEDIR.'/OtroDirectorio/DAO/usuario.php');
And in user.php
<?php
require(HOMEDIR.'/compra.php');
And the real good practice here is to use Composer and autoloading , so that the namespace of each class defines its location deterministically in the file tree, but sometimes it does not need to be complicated if you are experimenting or doing a proof of concept.