title: In php how do I call function from another class inside a different class?
body: <p>how do I call function from another class inside a different class?</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>    &lt;?php
  
      class database
      {
          private $host = "localhost";
          private $user = "root";
          private $password = "";
          private $db = "9dot";
  
          //connect to database
          public function connect()
          {
              $connect =  mysql_connect($this-&gt;host,$this-&gt;user,$this-&gt;password);
              $database = mysql_select_db($this-&gt;db,$connect);
  
          }
  
  
  
          //Get exam headers
          public function GetExam()
          {
              $this-&gt;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 .= "&lt;th&gt;ExamID&lt;/th&gt;";
              $table .= "&lt;th&gt;Name&lt;/th&gt;";
              $table .= "&lt;th&gt;Age&lt;/th&gt;";
              $table .= "&lt;th&gt;Position&lt;/th&gt;";
              $table .= "&lt;th&gt;Date&lt;/th&gt;";
  
              $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-&gt;connect();
              //$select = "SELECT ed.ExamDetailsID, ed.";
          }
  
  
          //Save Exam header
          public function SaveExam($firstname,$lastname, $age, $position)
          {
              $this-&gt;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()
          {
  
  
          }
  
  
  
      }
  
  ?&gt;
  
  
  
  
  
  &lt;?php
  
  include 'database.php';
  $database = new $database();
  
  class department
  {
      $database-&gt;//property or function
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>How do I call functions from database class</p>