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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:29:29+00:00 2026-05-16T14:29:29+00:00

i have 2 classes for DB for language i want to use my language

  • 0

i have 2 classes

  1. for DB
  2. for language

i want to use my language things in the DB
so it outputs the result

ex :

class db_control{

        var $db_connection, $lang_var;
        //create the function for the connection
        function db_connect(){
            //define some variables
            global $db_host, $db_username, $db_password, $db_name, $lang_var;
            $this->db_connection = mysql_connect("$db_host","$db_username","$db_password")or die("can't connect to server with these informations");
            //checl that the connection is established
            if($this->db_connection){
                echo $lang_vars->getvar("$langvals[lang_con_est]");
            }

but this

$lang_vars->getvar("$langvals[lang_con_est]");

doesn’t work
i mean it outputs many problems
and am sure my problem is that i didn’t define my variables and classes correctly

P.S : the language class is in file called language.php and this part is in DB.MySQL.php

EDIT :
this is the language class

class lang_vars{
    public static function getvar($variable){
        return $variable;
    }
}

i want the DB class to display text from the language class
thats why i used

 echo $lang_vars->getvar("$langvals[lang_con_est]");

but it doesn’t work
cuz when i declare the language class
$lang_vars = new lang_vars;
inside the db_control it shows error unexpected T_something expected T_Function
and when i declare it outside nothing up
hope i made things more clear now

  • 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-16T14:29:30+00:00Added an answer on May 16, 2026 at 2:29 pm

    Any reason why you are still using PHP4 syntax?

    When creating an instance of the db_control class, pass the object to be stored as $lan_var into the constructor or set it via a dedicated setter. See Dependency Injection.

    class DBControl
    {
        protected $_lang;
        public function __construct($lang = NULL)
        {
            if($lang !== NULL) {
                $this->_lang = $_lang;
            }
        }
        public function setLang($lang)
        {
            $this->_lang = $lang;
        }
    }
    

    Then do either

    $dbControl = new DBControl(new LangThing);
    

    or

    $dbControl = new DBControl;
    $dbControl->setLang(new LangThing);
    

    Also, get rid of the globals. Pass those in via Dependency Injection too.

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

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
I have some c++ OOP classes (separated files) , and I want to create
I have some classes layed out like this class A { public virtual void
I have multiple classes that all derive from a base class, now some of
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes that each need an instance of each other to function.
Right now I have classes like: abstract class Record { // Required fields val
I come from classes object orientation languages and recently I have been learning those
I have classes that store data, and methods to go get data for individual
From what I have read best practice is to have classes based on an

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.