为什么我的getLateInvoicesTotal函数返回以下错误的任何想法:
致命错误:未捕获错误:在布尔值上调用成员函数fetch_assoc()
此处有问题的函数:
function getLateInvoicesTotal() {
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
$query = "SELECT SUM(`total`) as `total` FROM invoices WHERE invoice_date < NOW() AND invoice_due_date > NOW() and AND status = 'open'";
// mysqli select query
$results = $mysqli->query($query);
while($row = $results->fetch_assoc()) {
$value = $row["total"];
$value = $value / 100;
setlocale(LC_MONETARY, 'en_GB.UTF-8');
$value = money_format("%.2n", $value);
print $value;
}
// Frees the memory associated with a result
$results->free();
// close connection
$mysqli->close();
}
唯一不同的是QUERY,因为我的Open发票功能运行正常,如下所示:
function getOpenInvoicesTotal() {
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
$query = "SELECT SUM(`total`) as `total` FROM invoices WHERE invoice_date < NOW() AND status = 'open'";
// mysqli select query
$results = $mysqli->query($query);
while($row = $results->fetch_assoc()) {
$value = $row["total"];
$value = $value / 100;
setlocale(LC_MONETARY, 'en_GB.UTF-8');
$value = money_format("%.2n", $value);
print $value;
}
// Frees the memory associated with a result
$results->free();
// close connection
$mysqli->close();
}
答案 0 :(得分:1)
您在状态行之前有一个双重问题:
$query = "SELECT SUM(`total`) as `total` FROM invoices WHERE invoice_date < NOW() AND invoice_due_date > NOW() and AND status = 'open'";
应该是
$query = "SELECT SUM(`total`) as `total` FROM invoices WHERE invoice_date < NOW() AND invoice_due_date > NOW() AND status = 'open'"