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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:41:57+00:00 2026-06-06T13:41:57+00:00

how do I call function from another class inside a different class? Here’s my

  • 0

how do I call function from another class inside a different class?

Here’s my current code:

    <?php

    class database
    {
        private $host = "localhost";
        private $user = "root";
        private $password = "";
        private $db = "9dot";

        //connect to database
        public function connect()
        {
            $connect =  mysql_connect($this->host,$this->user,$this->password);
            $database = mysql_select_db($this->db,$connect);

        }



        //Get exam headers
        public function GetExam()
        {
            $this->connect();
            $select = "SELECT e.ExamHeaderID, CONCAT(e.Firstname,' ',e.Lastname) AS Fullname e.Age, e.Position, e.Date FROM examheader e";
            $result = mysql_query($select);
            $table = "";
            $table .= "<th>ExamID</th>";
            $table .= "<th>Name</th>";
            $table .= "<th>Age</th>";
            $table .= "<th>Position</th>";
            $table .= "<th>Date</th>";

            $exam_id = "";
            $fullname = "";
            $age = "";
            $position = "";
            $date = "";
            while($row = mysql_fetch_array($select))
            {
                $exam_id = mysql_real_escape_string($row['ExamHeaderID']);
                $fullname = mysql_real_escape_string($row['Fullname']);
                $age = mysql_real_escape_string($row['Age']);
                $position = mysql_real_escape_string($row['Position']);
                $date = mysql_real_escape_string($row['Date']);
            }

        }

        public function GetExamDetails($ExamID)
        {
            $this->connect();
            //$select = "SELECT ed.ExamDetailsID, ed.";
        }


        //Save Exam header
        public function SaveExam($firstname,$lastname, $age, $position)
        {
            $this->connect();
            $date = date("m/d/Y");
            mysql_real_escape_string($firstname);
            mysql_real_escape_string($lastname);
            mysql_real_escape_string($age);
            mysql_real_escape_string($position);
            $insert = "INSERT INTO examheader (Firstname,Lastname, Age, Position, Date) VALUES ('$firstname','$lastname','$age','$position')";
            $result = mysql_query($insert);
            $exam_id = mysql_insert_id();
            //return exam id for insertion of exam details
            return $exam_id;

        }

        public function SaveExamAnswer()
        {


        }



    }

?>





<?php

include 'database.php';
$database = new $database();

class department
{
    $database->//property or function
}



?>

How do I call functions from database class

  • 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-06T13:41:59+00:00Added an answer on June 6, 2026 at 1:41 pm

    Try something like this (rough example):

    <?php
    
    include 'database.php';
    
    
    class department
    {
    
        public function doSomething() {
           $database = new $database();
           $val = $database->GetExam();
           //do something
        }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how you would call a getter function from another class in
I'm trying to call a function from inside the call of another function. If
I need help trying to call a class function within another class. Here's my
I'm trying to call a function present in one class from another class by
I've been working with JavaScript and i need to call a function from another
How do I call a function in one Clojure namespace, bene-csv.core from another namespace,
I am trying to use the call function from the Python library inside a
How can I call a function from inside the function, so it becomes recursive?
I'm trying to call a function from a form within the same .php file,
If I derive a class from another one and overwrite a function, I can

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.