I have a strange problem. I have one file index.php in the root, and 2 files include directory inside the root.
root > index.php , include
include > config.php , db.php
In include/db.php I defined MySQL connection parameters like this:
$hostname = 'localhost';
$username = 'root';
$password = '';
$dbname = 'mydb';
Then I have included this file inside include/config.php :
include 'db.php';
And finally, I've included include/config.php inside index.php .
The problem I have is I have not access to database variables when I run index.php . They are only available if I run include/config.php . But I expected I must have all defined variables inside these 2 files when I included them in index.php .
What is the problem ?
if you have included config.php in index.php and db.php in config.php. Then index.php should be: include 'include/config.php';
and config.php should be: include 'include/db.php';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.