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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:57:56+00:00 2026-06-05T03:57:56+00:00

I have error in my code: Fatal error: Call to a member function query()

  • 0

I have error in my code:
Fatal error: Call to a member function query() on a non-object in /var/www/crud_php/core/class_ManageDatabase.php on line 23

Error line: $query = $this->link->query("SELECT * FROM $table_name ORDER BY id ASC");

<?php

class ManageDb{
    public $link;

    function __construct() {
        include_once 'class_database.php';
        $conn = new database;
        $this->link = $conn->connect();

        return $this->link;
    }

    function getData($table_name, $id=null){
        if(isset($id)){
            $query = $this->link->query("SELECT * FROM $table_name WHERE id = '$id' ORDER BY id ASC");
        }else{
         **$query = $this->link->query("SELECT * FROM $table_name ORDER BY id ASC");**   
        }

        $rowCount = $query->rowCount();
        if ($rowCount >=1){
            $result = $query->fetchAll();
        }else{
            $result = 0;
        }

        return $result;
    }


}



?>

db connect:

<?php
include_once '../config.php';

class database {

    protected $db_conn;
    public $db_name = DB_NAME;
    public $db_host = DB_HOST;
    public $db_pass = DB_PASS;
    public $db_user = DB_USER;

    function connect() {
        try {
            $this->db_conn = new PDO("mysql:host = $this->db_host;dbname=$this->db_name", $this->db_user, $this->db_pass);
        } catch (PDOException $e) {
            return $e->getMessage();
        }
    }

}

?>
  • 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-05T03:57:57+00:00Added an answer on June 5, 2026 at 3:57 am

    It means $this->link is not an object. You forgot to return the connection in your connect() method. Add return $this->db_conn; in that method.

    On a side-note, returning a string in case of an error is a very bad idea. Let the exception propagate or terminate the script – but not return something completely else that will cause odd errors later in your code.
    You also cannot return anything from a constructor.

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

Sidebar

Related Questions

I'm getting: Fatal error: Call to a member function query() on a non-object in
I have the error of [12-Jul-2011 11:05:43] PHP Fatal error: Call to a member
this is my code and have a error: $('#map_canvas').mouseover(function(e){ console.log(e.offset().left+' '+e.offset().top) }) thanks i
I have CakePHP Controller code which is throwing up the following error 'Fatal error:
THE SUMMARY: When I call .../index.php/product, I receive: Fatal error: Call to a member
When I execute this code I get an error saying PHP Fatal error: Call
I have two subsequent mysqli statements, and the second returns: Fatal error: Call to
Hi everybody I have a code that give me this error Fatal error: Class
I have error handling code that is designed to catch unnhandled exceptions, and then
I have defined a simple int error code: #define my_error 20 Somewhere in my

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.