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 7517561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:29:32+00:00 2026-05-30T01:29:32+00:00

stuck on this. Lets start with code. Settings.php class settings{ public $db_host; public $db_username;

  • 0

stuck on this. Lets start with code.

Settings.php

class settings{

public $db_host;
public $db_username;
public $db_password;
public $db_database;

public function db_settings(){

    /*$db_host = "localhost";
    $db_username = "root";
    $db_password = "";
    $db_database = "eveonline";*/

    $this->db_host = "localhost";
    $this->db_username = "root";
    $this->db_password = "";
    $this->db_database = "eveonline";
}

This is where I want to use this

class xmlUpdate{

    include_once ('./lib/settings.php'); //This wont work
    public $itemCount;

    public function dbItemCount(){
    include_once ('./lib/settings.php');// This will work, but only in this function

In this case its for database varables, so I dont have to duplicate code whenever I want to make a database connection.

How can I use the database varables in another class, the whole class, not just the function where it allows me to include?

  • 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-30T01:29:35+00:00Added an answer on May 30, 2026 at 1:29 am

    I would put the include into the __construct() function of your class, instantiate a new Class, read out the variables put them in local variables in your class.

    class xmlUpdate{
    
        public $db_host;
        public $db_username;
        public $db_password;
        public $db_database;
    
    
        function __construct(){
            include_once('./lib/settings.php');
            $settings = new settings();
    
            $this->db_host = settings->db_host;
            $this->db_username= settings->db_username;
            $this->db_password= settings->db_password;
            $this->db_database= settings->db_database;
    
        }
    
    }
    

    Or you could make you xmlUpdate class extend the settings class.

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

Sidebar

Related Questions

Lets assume the following code within a controller: $this->view->addScriptPath('dir1/views/scripts'); $this->view->addScriptPath('dir2/views/scripts'); $this->render('index.phtml'); Where dir1/views/scripts contains
i am stuck with this small problem in my code. I am trying to
I'm kinda stuck with this one so I hoped someone could help me. I
I am stuck on this problem which I am studying for an exam tomorrow.
I'm stuck with this already for some weeks and I don't have the faintest
I have been stuck on this for days, and was wondering if anyone had
I'm kinda stuck on this decision. My project already uses Spring and Spring Blazeds
I've been stuck with this for weeks now and have no idea where I'm
I'm stuck with this. I'm self studying assenbler and translating some basics instructions. But
I've been stuck with this simple Sql query for last 3 hours and my

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.