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

  • Home
  • SEARCH
  • 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 284683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:28:45+00:00 2026-05-12T05:28:45+00:00

I have some database information stored in config.inc.php and i’m trying to use it

  • 0

I have some database information stored in config.inc.php and i’m trying to use it to access the database in a class I have, but for some reason, the variables are null. heres the code:

<?php

require_once 'dbinterface.php';
require_once 'config.inc.php';

class user {

    ...

    function user($id) {
        $this->db = new db($DB['host'], $DB['user'], $DB['pass'], $DB['database']);
        ...
    }
...
?>

and here’s config.inc.php:

<?php

$DB['host'] = '192.168.1.107';
$DB['user'] = '****';
$DB['pass'] = '****';
$DB['database'] = 'qa';

?>

I’m not sure why i’m getting nulls, but here’s my proof:

Fatal error: Uncaught exception
‘Exception’ with message ‘No database
selected’ in
D:\development\PHP\qanda\dbinterface.php:18
Stack trace: #0
D:\development\PHP\qanda\user.class.php(17):
db->db(NULL, NULL, NULL, NULL) #1
D:\development\PHP\qanda\log.php(17):
user->user(‘1’) #2 {main} thrown in
D:\development\PHP\qanda\dbinterface.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-05-12T05:28:45+00:00Added an answer on May 12, 2026 at 5:28 am

    You would have to declare $DB as global for this to work:

    global $DB;
    
    $DB['host'] = '192.168.1.107';
    $DB['user'] = '****';
    $DB['pass'] = '****';
    $DB['database'] = 'qa';
    

    And in your class definition:

    function user($id) {
            global $DB;
            $this->db = new db($DB['host'], $DB['user'], $DB['pass'], $DB['database']);
            ...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some EDI messages (X12, HL7, etc ...) stored in an Oracle database.
I'm responsible for some test database servers. Historically, too many other poeple have access
I have a huge database with some 100 tables and some 250 stored procedures.
I have a quick (hopefully simple) question. I have some information stored in a
I have some data files to import into a database with some unique delimiters:
I have some strings that I am pulling out of a database and I
I have some existing code that retrieves data from a database using ADO.NET that
Suppose I have some application A with a database. Now I want to add
Does anyone have some good hints for writing test code for database-backend development where
I have a Linux web server and I'd like to make some database tables

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.