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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:49:19+00:00 2026-06-16T01:49:19+00:00

I am converting a my site to PDO and after about 200 scripts I

  • 0

I am converting a my site to PDO and after about 200 scripts I am very near the end. Every script accesses the same functions script. Within the functions script I have a Database class which looks like so:

class Database {
    private $db_con = ''; //stores the connection

    public function db_login(){
        //log into the database
    }
    public function db_control($query, $params){
        //run the query
    }
}
//initiate the class and log in
$db = new Database();
$db->db_login();

Both of these functions work fine and for every type of query, hence why I am almost finished. However, I have run into a problem.

I have a standalone function on a script I am working on which is used several times within the script. I usually run the db_control:

$results = $db->db_control($query, $params);

But running it from within a function:

function func(){
    $results = $db->db_control($query, $params);
}

Returns the error.

Fatal error: Call to a member function db_control() on a non-object in
C:….php on line 39

What am I doing wrong? The class is definitely being initiated as other queries on the script work fine when this function is removed. How can I access db_control() from within a standalone function?

Thank you,
Joe

  • 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-06-16T01:49:20+00:00Added an answer on June 16, 2026 at 1:49 am

    $db is not available within the function scope, you could

    Pass $db as an argument

    function func($db, $query, $params){
        return $db->db_control($query, $params);
    }
    $results = func($db, $query, $params);
    

    Or

    function func($query, $params){
        global $db;
        return $db->db_control($query, $params);
    }
    $result = func($query, $params);
    

    Use global to make it available within the function, there’s probably other solutions too!

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

Sidebar

Related Questions

I am currently converting a very old, but working classic ASP site to ASP.Net.
I'm just converting a site to PDO and this is my first exposure to
I have a PHP/MySQL site I'm thinking about converting into a HTML5/JavaScript that could
After converting my site to use utf-8, I'm now faced with the prospect of
After converting my Web Site Project to a Web Application Project , some of
I am converting a personal site over to MVC 2 and I have been
I am trying to fix an ASP.NET site that a friend had botched converting
After converting project to ARC, The converting operation removed all the - assign, retain
I'm converting a site over from Wordpress to a custom CMS and I'm trying
I'm in the final stages of converting our site over to Graph API from

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.