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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:32:22+00:00 2026-05-28T06:32:22+00:00

The Situation I have a table in a DB that contains job types, basically

  • 0

The Situation

I have a table in a DB that contains job types, basically defined by a label and a price. I’m trying to do a simple SELECT * FROM jobtype but I can’t seem to get it to work, although I’ve use the same block over and over again in the rest of the code. The main difference here, is that it is a singleton trying to execute the function.

The problem is that as soon as I uncomment the line $rs_job_types = mysql_query($query_job_types, $vtconnection) or die(mysql_error()); the page will stop loading at this particular point in the code.

The Code

Following is the code of my function getJobTypes():

require_once('Connections/vtconnection.php');
class JobTypes extends Singleton{
    static private $job_types;

    public static function getJobTypes(){
        if (self::$job_types == null){
            echo 'DEBUG: For now, $job_types is NULL.'."\n";
            mysql_select_db($database_vtconnection, $vtconnection);
            $query_job_types = 'SELECT * FROM jobtype';
            $rs_job_types = mysql_query($query_job_types, $vtconnection) or die(mysql_error());

            while ($rs_row = mysql_fetch_assoc($rs_job_types)){
                // let the job type identifier in the db be its index in our array
                self::$job_types[$rs_row['id']]['label'] = $rs_row['label']; // job type label
                self::$job_types[$rs_row['id']]['price'] = $rs_row['price']; // job type price
            }
            if (self::$job_types != null) echo 'DEBUG: $job_types has been populated.'."\n";
        }
        return self::$job_types;
    }
}

Which I am calling like so:

$jt = JobTypes::getJobTypes();

Here is my singleton pattern:

class Singleton{
    private static $instances = array();

    final private function __construct(){
    }

    final public function __clone(){
        trigger_error('You don\'t clone a singleton!', E_USER_ERROR);
    }

    final public static function getInstance(){
        $c = get_called_class();
        if(!isset(self::$instances[$c])){
            self::$instances[$c] = new $c;
        }
        return self::$instances[$c];
    }
}

I have turned the problem in my head, commented everything inside the getJobtypes() function and uncommented step by step. I found out the problem does happen with the mysql_query() line, just can’t seem to work out why. Is something obviously wrong in my code?


Solved

As suggested here, I used global $vtconnection,$database_vtconnection; at the start of my static function and all went smooth. It is not an optimal solution but it pointed out the scope issue which I will now try to resolve.

I also got rid of the singleton pattern.

  • 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-28T06:32:23+00:00Added an answer on May 28, 2026 at 6:32 am

    Well the most obvious thing is $database_vtconnection $vtconnection are defined nowhere in your getJobTypes function. If they’re part of the class, you need $this (object) or self (static) references. More likely it looks like you’re trying to use global variables, in which case you have to pull them into the scope of the function.

    mysql_select_db can auto-connect (if $vtconnection isn’t supplied) but only if it knows how – there’s a previous connection (or possible INI config with db/host/user/pass).

    To pull them into scope you need to add the line at the beginning of the function:

    global $vtconnection,$database_vtconnection;`
    

    … Or use the $GLOBALS superglobal array:

    mysql_select_db($GLOBALS["database_vtconnection"],$GLOBALS["vtconnection"]);
    

    For the record using globals isn’t a particularly good solution.

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

Sidebar

Related Questions

Here is my situation: I have one table that contains a list of drugs
I have a GridView that is bound to a select statement from a table.
I have a situation where I have a table that has a soft foreign
I have this situation: I have an entity, Person , that contains all personal
Here's the situation I'm in: We have a field in our database that contains
I have a process A that contains a table in memory with a set
I have a table in a database that contains a variety of paths to
I have a report that contains a table of data this data is set
I have a rdcl ready to be populated. It mainly contains a table that
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #

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.