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 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 am using this plugin. However it seems to use global variables $.blockUI(); $.unblockUI();
To start out with - this is not my code - there was a
My question is I am using the variable $db in my general script code
I have a unit tests for Zend Framework controllers extending Zend_Test_PHPUnit_ControllerTestCase . The tests
In my previous post i ask how to create variables from an array (
I have created a WCF REST style service in my project. In development I
I feel that ParseActions make my code a bit clunky when trying to construct
Is there a way for me to use a functionality similar to what are
I am constructing a little app in javascript right now but I've clashed into
I'm working on a little application that multiples an array with a Matrix. It

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.