title: OOP php error in database connection
body: <p>i'm new to OOP so i'm following a tutorial. so in that it uses following codes to connect to the database but in my case it is not connecting </p>
  
  <p>databas.php </p>
  
  <pre><code>&lt;?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);
          }
      }
  
      public function query($sql) {
          $result = mysql_query($sql, $this-&gt;connection);
          $this-&gt;confirm_query($result);
          return $result;
      }
  
      public function mysql_prep( $value ) {
          $magic_quotes_active = get_magic_quotes_gpc();
          $new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP &gt;= v4.3.0
          if( $new_enough_php ) { // PHP v4.3.0 or higher
              // undo any magic quote effects so mysql_real_escape_string can do the work
              if( $magic_quotes_active ) { $value = stripslashes( $value ); }
              $value = mysql_real_escape_string( $value );
          } else { // before PHP v4.3.0
              // if magic quotes aren't already on then add slashes manually
              if( !$magic_quotes_active ) { $value = addslashes( $value ); }
              // if magic quotes are active, then the slashes already exist
          }
          return $value;
      }
  
      private function confirm_query($result) {
          if (!$result) {
              die("Database query failed: " . mysql_error());
          }
      }
  
  }
  
  $database =&amp; new MySQLDatabase();
  $db =&amp; $database;
  
  ?&gt;
  </code></pre>
  
  <p>config.php</p>
  
  <pre><code>&lt;?php
  
  // Database Constants                             
  defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
  defined('DB_USER')   ? null : define("DB_USER", "oop_project");
  defined('DB_PASS')   ? null : define("DB_PASS", "");
  defined('DB_NAME')   ? null : define("DB_NAME", "oop_project");
  
  ?&gt;
  </code></pre>
  
  <p>function.php</p>
  
  <pre><code>&lt;?php
  
  function strip_zeros_from_date( $marked_string="" ) {
    // first remove the marked zeros
    $no_zeros = str_replace('*0', '', $marked_string);
    // then remove any remaining marks
    $cleaned_string = str_replace('*', '', $no_zeros);
    return $cleaned_string;
  }
  
  function redirect_to( $location = NULL ) {
    if ($location != NULL) {
      header("Location: {$location}");
      exit;
    }
  }
  
  function output_message($message="") {
    if (!empty($message)) { 
      return "&lt;p class=\"message\"&gt;{$message}&lt;/p&gt;";
    } else {
      return "";
    }
  }
  
  ?&gt;
  </code></pre>
  
  <p>when i going to test the connection 
  i got these errors.</p>
  
  <pre><code>Deprecated: Assigning the return value of new by reference is deprecated in J:\xampp\htdocs\oop_project\includes\database.php on line 60
  
  Deprecated: Assigning the return value of new by reference is deprecated in J:\xampp\php\PEAR\Config.php on line 80
  
  Deprecated: Assigning the return value of new by reference is deprecated in J:\xampp\php\PEAR\Config.php on line 166
  
  Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in J:\xampp\htdocs\oop_project\includes\database.php on line 13
  
  Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in J:\xampp\htdocs\oop_project\includes\database.php on line 13
  
  Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in J:\xampp\htdocs\oop_project\includes\database.php on line 13
  
  Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in J:\xampp\htdocs\oop_project\includes\database.php on line 13
  
  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 J:\xampp\htdocs\oop_project\includes\database.php on line 13
  
  Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in J:\xampp\htdocs\oop_project\includes\database.php on line 13
  Database connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known.
  </code></pre>
  
  <p>how can i correct this...? thank you.</p>