title: Why do I still need to declare require_once('../config.php') in index.php?
body: <p>I have <strong>database.php</strong> that already has <code>require_once('../config.php')</code> inside it.
  I don't understand why I still need to put both <code>require_once('../config.php')</code> and <code>require_once('../database.php')</code> in my <strong>index.php</strong> instead of <code>require_once('../database.php')</code> only since <code>require_once('../config.php')</code> is already inside <strong>database.php</strong>?  </p>
  
  <p>If I remove <code>require_once('../config.php')</code> in the <strong>index.php</strong> I am getting error.</p>
  
  <pre><code>&lt;pre&gt;Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in C:\xampp\htdocs\lyndaphoto\includes\database.php on line 18
  
  Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in C:\xampp\htdocs\lyndaphoto\includes\database.php on line 18
  
  Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in C:\xampp\htdocs\lyndaphoto\includes\database.php on line 18
  
  Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\lyndaphoto\includes\database.php on line 18
  
  Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://DB_SERVER:3306) in C:\xampp\htdocs\lyndaphoto\includes\database.php on line 18
  
  Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\lyndaphoto\includes\database.php on line 18&lt;/pre&gt;
  
  config.php
  $server = "localhost";
  $user = "root";
  $db_pass = "password";
  $db_name = "photo_gallery";
  
  define("DB_SERVER", $server);
  define("DB_USER", $user);
  define("DB_PASS", $db_pass);
  define("DB_NAME", $db_name);
  
  
  database.php
  
  require_once("config.php");
  
  class MySQLDatabase {
  
  
  private $connection;    
  
  function __construct() {
  $this-&gt;open_connection();
  }
  
  public function open_connection() {
  $this-&gt;connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
  if (!$this-&gt;connection) {
  die("Database connection failed: " . mysql_error());
  }else {
  $db_select = mysql_select_db(DB_NAME, $this-&gt;connection);
  if (!$db_select) {
  die("Database selection failed: " . mysql_error());
  }
  }
  }
  
  public function close_connection() {
  if(isset($this-&gt;connection)) {
  mysql_close($this-&gt;connection);
  unset($this-&gt;connection);
  }
  }
  }
  
  $database = new MySQLDatabase();
  $db =&amp; $database;
  </code></pre>
  
  <p>both files are on "localhost/photogallery/includes/"
  Thanks in advance! :)</p>