I am trying to get the (float) value from a database, but when I print the result it is showing as 'Array' instead of the value (20).
Here is the code:-
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->fetchAll();
$stmt->closeCursor();
print_r($result[0]);
return $result;
$dbh = null;
}
catch (PDOException $pe) {
die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
}
}
I know it is only selecting one value and shouldn't return an array of values. I believe the issue is $stmt->fetchAll();
, but I'm not quite sure what this needs to be changed to?