How to display single SQL query results in PHP
P粉852578075
2023-08-17 20:30:29
<p>I have a query about this php code and cannot display the results in echo, can I convert to string? </p>
<pre class="brush:php;toolbar:false;">//conexion is my function to connect to the database and has been completed
$costTotal=conexion();
$costTotal=$costTotal->query("SELECT SUM(product_cost) FROM product");
echo $costTotal;</pre>
<p>For example, the desired result is <code>string(5)"18000"</code></p>
$costTotal
contains the result of the database query, it is not a string, but you are usingecho
. To output the results as a string, you need to get the data from the query results.