run function in another php file w/o using require or includ

how do i run a function declared in another php file without using “include” or “require”?

for example (below) file1.php contains function connectToDB() which accesses db.conf file to get connection details for my database, then connects to the database. the problem is that if i need to use the function connectToDB() in file2.php, i cannot use “include(’…/file1.php’)” or “require…”, because it will try to find folder1.2>folder1.1>db.conf instead of folder1.1>db.conf.


so i can’t use “include” or “require”. what do you suggest? thanks

or i can rephrase my question to “how do i run connectToDB() (declared in file1.php) in file2.php as if it was run from file1.php?”


As far as I know this impossible… How would you run a function from page 1 in page 2, if there is no reference what so ever.

I guess my best suggestion would be to use absolute paths.


Then no matter where you run the file it will start from the root directory and work up. I think that would be the easiest and best option over relative paths.

Also, you can look at $_SERVER[‘DOCUMENT_ROOT’] to help with the path.

Sponsor our Newsletter | Privacy Policy | Terms of Service