Use of undefined constant - Xampp 1.8.1

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Use of undefined constant - Xampp 1.8.1

Postby ianonyk » 09. April 2013 09:50

I'm using Xampp and I got this frustrating error and couldn't figure out how to fix it.
Code: Select all
Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in C:\xampp-portable\htdocs\gallery\includes\database.php on line 12


Here is my index.php file located in "gallery/public/" folder
Code: Select all
<?php
require_once("../includes/database.php");

if (isset($database)){
echo "Is this working?";
}
?>


Here is the config.php located in "gallery/includes/" folder
Code: Select all
<?php
define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'photo_gallery');
?>


and here is the database.php located in "gallery/includes/" folder
Code: Select all
<?php
require_once("config.php");
class MySQLDatabase {
   
   private $connection;
   
  function __construct() {
    $this->open_connection();
  }

   public function open_connection() {
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
      if (!$this->connection) {
         die("Database connection failed: " . mysql_error());
      } else {
         $db_select = mysql_select_db(DB_NAME, $this->connection);
         if (!$db_select) {
            die("Database selection failed: " . mysql_error());
         }
      }
   }

   public function close_connection() {
      if(isset($this->connection)) {
         mysql_close($this->connection);
         unset($this->connection);
      }
   }
}

$database = new MySQLDatabase();
$db =& $database;

?>
ianonyk
 
Posts: 2
Joined: 09. April 2013 09:47
Operating System: Window 7 64

Re: Use of undefined constant - Xampp 1.8.1

Postby Altrea » 09. April 2013 10:35

Just a test:
please rename your file config.php to something very unique like config123.php and change the require statement too.
I guess it is conflicting with the config.php file inside of PHP PEAR.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Use of undefined constant - Xampp 1.8.1

Postby ianonyk » 09. April 2013 12:29

That works. Thanks. But do you have any other solution that do not require renaming config.php?
Something with BASE magic varible?
ianonyk
 
Posts: 2
Joined: 09. April 2013 09:47
Operating System: Window 7 64

Re: Use of undefined constant - Xampp 1.8.1

Postby Altrea » 09. April 2013 15:40

ianonyk wrote:That works. Thanks. But do you have any other solution that do not require renaming config.php?
Something with BASE magic varible?

Two more possible solutions:
  • require your file with
    Code: Select all
    require dirname(__FILE__) . '/config.php';
  • remove PEAR from the php.ini include_path setting, if you will never need it

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 122 guests