P粉7970046442023-08-18 09:57:17
$costTotal
contains the result of the database query, it is not a string, but you are using echo
. To output the results as a string, you need to get the data from the query results.
$connection = connexion(); $query = "SELECT SUM(product_cost) as total FROM product"; $result = $connection->query($query); $data = $result->fetch(PDO::FETCH_ASSOC); $costTotal = $data['total']; echo $costTotal;