1

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 ?

Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127

1 Answers1

0

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';

SuperDJ
  • 7,488
  • 11
  • 40
  • 74