0

Hello Guys can anyone explain why is this happening to my program

when i use this Folder structure

enter image description here

and the code inside database.php is

<?php require_once("../db_config.php");?>

I get an error Fatal error: require_once(): Failed opening required '../db_config.php' (include_path='.;F:\xampp\php\PEAR') in F:\xampp\htdocs\project\database\db_mysql\database.php on line 3'

but when i move the db_config.php

enter image description here

Everything works fine. I don't get it. Can anyone explain.I prefer to use the first Folder structure because i will add a new folder db_mssql for mssql database.

2
  • I believe you are on windows and windows prefers backslash to forwardslash Commented Feb 6, 2013 at 2:56
  • @Satya thanks but i use all forwardslash in my links and it still working. Commented Feb 6, 2013 at 3:00

1 Answer 1

3
<?php require_once("../db_config.php");?>

Try

<?php require_once("../../db_config.php");?>

Better yet use

require_once($_SERVER['DOCUMENT_ROOT'] . 'directory/directory/file');
Sign up to request clarification or add additional context in comments.

2 Comments

require_once($_SERVER['DOCUMENT_ROOT'] . '/directory/directory/file'); Thanks this one works. But this code <?php require_once(" ../db_config.php");?> doesn't work? can you explain why?
The ../ is the equivilent of a directory in the directory structure. Each one tells the code to look up to its parent directory. db_config.php is located 2 directories(including the one that it is located in) higher than database.php. It's like folderception!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.