如何从另一个类中的另一个类调用函数?
这是我当前的代码:
<?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
}
?>
如何从数据库类调用函数