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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:43:25+00:00 2026-05-23T08:43:25+00:00

I have a problem. When I use global variables in my php code, my

  • 0

I have a problem. When I use global variables in my php code, my server doesn’t show any html code at all. If I comment out the global variable, my html page works just fine! Am I doing something wrong here?

php file:

class DBConnect{

    // If I comment this out, the HTML shows
    global $con;

    function connectDB() {
        $user = "bstokni_basurin";
        $pass = "basurin";
        $database = "basurin";
        $host = "localhost";

        $this->$con = mysql_connect($host, $user, $pass) or die(mysql_error());
        echo "Connected to MySQL </br>";
        echo $con;
    }

    function closeDB() {
        mysql_close($con);
        echo $con;
        echo "MySQL closed";
    }   
}

html file:

<!-- Left colon -->
            <div id="leftCol">
                <p>Her kemur ein menu at standa</p>
                <?
                    $menuObj = new DBConnect();
                    $menuObj->connectDB();
                ?>
            </div>

What am I doing wrong here?

  • 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-23T08:43:26+00:00Added an answer on May 23, 2026 at 8:43 am

    Since the variable is in a class scope, try changing global to public instead. You don’t seem to need global in the example you have provided.

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

Sidebar

Related Questions

I have the following PHP code which works out the possible combinations from a
I have found a problem with use JQuery timeout, i have a page with
I have a problem with a bash script. I have to use the operator
I still have a problem with the splash screen. I don't want to use
I have hit upon this problem about whether to use bignums in my language
If I have a choice to use recursion or memoization to solve a problem
I have this .bat script which I use to maven package my application. Problem
I've just started to use linq to sql and have run into a problem
I'm having a strange problem. I have to use GetPostBackEventRefence to force a Postback,
I have run into a common, yet difficult problem. I do not use Photoshop

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.