I have this code.
<?php
$link = new mysqli("localhost","root", "SENHAAAA", "BANCO");
$sql_saldo_total = $link->prepare(
"SELECT sum(g) saldo_total
FROM ( SELECT SUM(valor_pg) g
FROM tabela1
WHERE departamento = ?
AND MONTH(data_pg) <= ?
AND YEAR(data_pg) = ?
AND
UNION ALL
SELECT SUM(valor)
FROM tabela2
WHERE tipo = ?
AND MONTH(data) <= ?
AND YEAR(data) = ?
) tabela_virtual");
$sql_saldo_total->bind_param("siisii",
$departamento,
$mes,
$ano,
$departamento,
$mes,
$ano);
?>
But it is returning the error:
Fatal error: Call to a member function bind_param() on a non-object in