I am new to PHP and would like to ask, what will be the best possible way to declare application level variables and database connection strings or configurations?
How are these application level variables accessible to my scripts?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s commonplace (at time of writing) to store connection information in constants, in a file named
config.phpor similar. Due to the sensitive nature of the file’s contents, it’s also a good idea to store this file outside of the web root.So you would have, in
config.php:And then to use in your scripts:
Presuming your
config.phpis in the same directory as your script.