The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

require_once not finding file

I've structured my sites by defining functions that build certain elements within the site. I then simply call the relevant functions depending on the page. To make things simpler I have a page called holding_fns.php which simply uses the require_once function to include different subsets of functions ie. user authentication functions, display functions etc. That way each page only needs to include this one script in order to include all the functions it might need. HOWEVER...
I have a set of functions contained within a file called db_fns.php. This (obviously!) contains functions that relate to the database - specifically the function that opens a connection with the database. As such it has a username and password combination to allow this.
I would like, for obvious reasons, to move this file out of the public_html tree on my hosted server. I thought I could do this by using the following code:

require_once('../db_fns.php');

but for some reason this breaks the holding_fns.php script.
I thought this was straight forward. Any ideas why it's not working?!?!

Thanks Mittineague. I think I understand what you're getting at. However, I'm not sure that's the problem.
The file db_fns file only has one function in it - the function that is called when a database connection is required. Surely this means that even if, as you say, the database can't be accessed from outside the root it doens't matter cos all I'm by the time the function is called it will have been required into another file. Does that make sense?
Are you suggesting I place the information needed to connect as variables in a file db_data.php, place that outside the root, then request that file into db_fns and use the variables within the function?

Just tried it and it's still not happy. Because the function in db_fns now includes the require_once for db_data the site only breaks once the function is called. Still basically the same problem though. Getting a bit frustrating... Isn't this that any site with a database has to do?!?!?!

To help you understand relative filepaths and how php tries to resolve them, make use of getcwd(). The value returned by getcwd() is the directory which php will try to resolve a relative file path from(well, it may also try to use the include path too, but lets ignore that for now).

If your host support $_SERVER['DOCUMENT_ROOT'] use it then remove the last directly and use it as your private root. Then anything that is above the site root simple place them together and you have a nice absolute path. Simple example: