我有一个名为 TariffFareController 的类,我从数据库中获得了正确的票价,如下所示:-
class TariffFareController {
public static function getTourFare($fieldTour) {
$pdo = new SQL();
$dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);
try {
$query = "SELECT Fare FROM tbltours
WHERE TourName = '$fieldTour'";
$stmt = $dbh->prepare($query);
$stmt->execute();
$result = $stmt->fetchColumn();
$stmt->closeCursor();
return $result;
$dbh = null;
}
catch (PDOException $pe) {
die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
}
}
}
然后我希望能够在我的私人 get fare 函数中检查结果:-
private static function getFare($int_terminate) {
// $tour_fare = (the result from getTourFare)
if ($tour_fare != null) {
// do something
}
else {
// do something else
}
}
我将如何从 getTourFare 获取 $result 并在私有 getFare 函数中使用它?
任何帮助将非常感激!