0

My database config class file is bellow

pard_config/class/Config.php

pard_config is a folder which is in the root folder.

And i have a json file which contain,host name,database,user and password details

pard_config/class/config.json 

How would i include Config.json file to the Config.php file without reading it from the root.For now i'm doing it like bellow

Config.php

include("pard_config/class/config.json");

Config.json and the config.php files are in the same folder.So is there any way to read from that class folder like bellow ???

Config.php

include(config.json);

1 Answer 1

2

I would advice you to use a relative path and use the __DIR__ constant:

include(__DIR__ . '/config.json');

note that paths will be resolved from the script which where called in browser (or command line) .. like index.php. Therefore it will suite better in many cases to use a relative path.

Sign up to request clarification or add additional context in comments.

Comments

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.