Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:19:31+00:00 2026-06-10T20:19:31+00:00

I have a database class in which I am calling a config file using

  • 0

I have a database class in which I am calling a config file using required_once. In that I have declared some constants using define(). I am getting errors of Undefined constant and also assigning the return value of new by reference. Here is the config file code:

<?php

// Database Constants
defined("DB_SERVER") ? null : define("DB_SERVER", "localhost");
defined("DB_USER")   ? null : define("DB_USER", "root");
defined("DB_PASS")   ? null : define("DB_PASS", "");
defined("DB_NAME")   ? null : define("DB_NAME", "shareysmile");

?>

and here is my database class code (Both are in same directory so that’s not the problem):

<?php
require_once("config.php");

class MySQLDatabase {

    private $connection;
    public $last_query;
    private $magic_quotes_active;
    private $real_escape_string_exists;

  function __construct() {
    $this->open_connection();
        $this->magic_quotes_active = get_magic_quotes_gpc();
        $this->real_escape_string_exists = function_exists( "mysql_real_escape_string" );
  }

    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);
        }
    }

    public function query($sql) {
        $this->last_query = $sql;
        $result = mysql_query($sql, $this->connection);
        $this->confirm_query($result);
        return $result;
    }

    public function escape_value( $value ) {
        if( $this->real_escape_string_exists ) { // PHP v4.3.0 or higher
            // undo any magic quote effects so mysql_real_escape_string can do the work
            if( $this->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( !$this->magic_quotes_active ) { $value = addslashes( $value ); }
            // if magic quotes are active, then the slashes already exist
        }
        return $value;
    }

    // "database-neutral" methods
  public function fetch_array($result_set) {
    return mysql_fetch_array($result_set);
  }

  public function num_rows($result_set) {
   return mysql_num_rows($result_set);
  }

  public function insert_id() {
    // get the last id inserted over the current db connection
    return mysql_insert_id($this->connection);
  }

  public function affected_rows() {
    return mysql_affected_rows($this->connection);
  }

    private function confirm_query($result) {
        if (!$result) {
        $output = "Database query failed: " . mysql_error() . "<br /><br />";
        //$output .= "Last SQL query: " . $this->last_query;
        die( $output );
        }
    }

}

$database = new MySQLDatabase();


?>

I can’t understand the problem, can anyone help? Here are the exact errors I get:

Deprecated: Assigning the return value of new by reference is deprecated in D:\xampp\php\PEAR\Config.php on line 80

Deprecated: Assigning the return value of new by reference is deprecated in D:\xampp\php\PEAR\Config.php on line 166

Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in D:\xampp\htdocs\sharesmile\src\database.php on line 18

Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in D:\xampp\htdocs\sharesmile\src\database.php on line 18

Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in D:\xampp\htdocs\sharesmile\src\database.php on line 18
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:19:33+00:00Added an answer on June 10, 2026 at 8:19 pm

    It would appear that the config.php you are including includes D:\xampp\php\PEAR\Config.php, not your config file. This is due to the PEAR directory having a higher priority than . in your include path. Use the absolute path (__DIR__ . '/config.php') to make it work reliably, or change your include path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DAO class which I am using to do database operations. I
I have a class which defines a historical extraction on a database: class ExtractionConfiguration
I have a database class, which manages all my mysql connections for my application.
Hi i have a class which contains different methods for checking database values. Each
I have a class with like 20 fields which get populated from SQL database
I have following situation - Have a MongoService class, which reads host, port, database
I have a WCF service with a security class for getting some of the
I have a class Page that creates an instance of DB , which is
I have a database class that I made that uses PDO to connect to
Okay, so I have a database project for my database class. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.