Question

I have 2 PHP files.

Connection.php : Contains a static function which would return a connection $con.

User.php: Manipulates a User's data (Database) which also requires the Connection.php in its script so it can connect to the database.

However this returns an error:

Warning: require_once(./Connection.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Classes\User.php on line 2

Fatal error: require_once(): Failed opening required './Connection.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Classes\User.php on line 2

UPDATE

Here's the directory:

/htdocs/Register.php <--I need to require both files here
/htdocs/Classes/User.php
/htdocs/Classes/Connection.php

When User.php is requiring Connection.php:

require_once './Connection.php';

When I'm requiring both files in Register.php:

require_once './Classes/Connection.php'; //No error when required Alone
require_once './Classes/User.php'; //No Error when required Alone
Was it helpful?

Solution

You must have to create folder inside the htdocs

Make sure your files are in current folder.

require_once("Classes/Connection.php");
require_once("Classes/User.php");

// call static function from Connection.php

$con = new Connection();
$con->connection(return values);

OTHER TIPS

require_once './Classes/Connection.php'; //No error when required Alone
require_once './Classes/User.php'; //No Error when required Alone

The above seems just about right, If you are getting error when requiring both files at the same, if is because you are having another file which you are requiring in User.php So, check, both files do not require anything at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top