Hidding MySQL connection data

Good day,

In order to avoid undesired access to sensible information of database connection (name, password, …) , I was suggested to create a new .php file and save it in a directory out of the root, where is unaccessible to web users.
I did it, and now I have to include this file in all .php files needing to connect to MySQL database.

My question is, how can I refer this directory where the “password” file is?
In other words, how is the syntaxis of the line to refer it (to write the include sentence)?

Here the directories:
php_library (where the file with the password information is)
www (website root)
spanish (where the .php files are, referring the "password"file through an onclude sentence)

Thanks a lot!!!


Let’s say you have the following file structure:


In your index.php file, you would just use “include” as you normally would:

include '../php_library/db.php';

Just because the user can’t access the folder, doesn’t mean PHP can’t see it.

If you wanted, you could use an absolute path, instead:

include 'full/absolute/path/to/php_library/db.php';

And if you’re not sure of the absolute path, you can use the FILE magic constant:

echo __FILE__; // echos the full path and filename of the current file


This website has been developed using HTML/CSS, so I dont have an index.php file … but an index.html one …
The first .php file is under www/spanish folder

Should I then add this include sentence in this .php file?

Thanks a lot!!!

shortest answer is the include in that php file …/…/php_library/db.php but it might be smarter to use full path so that you can move that file around and not worry about editing it in the future


Yes, I tried with this sentence:
include ‘…/…/php_library/database.php’;

Is is properly written? I got an error message:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/libroman/public_html/spanish/dsstgo.php on line 13

Thanks a lot!!

It’s all fine now. It was my mistake!!!

Thanks a lot!!!