简体   繁体   中英

PHP directories including database file

I have a member_config file that has all of my functions in it.

At the top of this page, i call include_once('configuration/db.php'); .

I include my header.php file in my main.php file to load the navigation and such.

In my header file, I require a function from my member_config.php file.

At the top of my header.php, I need to include my memebr_config.php file so it can read my functions.

When I try to add require_once('../configuration/member_configuration/member_config.php'); at the top of my header, it's not getting the database file. An error shows : include_once(configuration/db.php): failed to open stream: No such file or directory in configuration\\member_configuration\\member_config.php on line 2

Because my member_config file is in a different directory, it doesn't allow me to call the member_config file due to the db.php not allowing the correct file location in the member_config from the header.php

Anyone know how to overcome this issue ?

FILE PATHS:

member_config.php = configuration/member_configuration/member_config.php

header.php = includes/header.php

db.php = configuration/db.php

Assuming Document Tree is

.
├── configuration
│   ├── db.php
│   └── member_configuration
│       └── member_config.php
├── includes
│   └── header.php
└── main.php

includes/header.php

<?php
include_once "configuration/member_configuration/member_config.php";
echo "<pre>";
echo "header.php".PHP_EOL;
?>

main.php

<?php
include_once "includes/header.php";
echo "main.php".PHP_EOL;
?>

configuration/db.php

<?php
echo "<pre>";
echo "db.php".PHP_EOL;
?>

configuration/member_configuration/member_config.php

<?php
include_once "configuration/db.php";
echo "mc donfig functions here".PHP_EOL;
?>

Calling main.php in the browser will output

db.php
mc donfig functions here
header.php
main.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM