在使用 adodb 存储的 mysql 列中查找总和的 PHP 代码可能有什么问题?

What might the problem in this PHP code to find Sum in mysql column stored using adodb?

我试图在 mysql table 中找到一列的总和,但出现如下错误。

    <?php   require_once("../../../../512/1.001/data/class.php"); 
$sql=mysqli_query($db,"select SUM(tbl_ccp_loans.payableamount) AS total");  $row = mysqli_fetch_assoc($sql); 
$sum = $row['total'];
$sum;?>

我预计总和是 'Number' 但输出是

Warning: mysqli_query() expects parameter 1 to be mysqli, object given in /home/testing/public_html/orrf/bej/ccp-main2/_dashboard/data.php on line 223

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/testing/public_html/orrf/bej/ccp-main2/modules/_dashboard/data.php on line 224

函数 mysqli_query() expects as first parameter object of mysqli class (returned by mysqli_connect()),但根据您注释中的代码,您的 $db 变量是不同 class 的对象。如果这是自定义 class,请尝试使用此 class 中的适当方法来执行查询并检索结果。

接下来是使用 mysqli_connect() 的基本示例。

<?php   
require_once("../../../../512/1.001/data/class.php"); 

$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

$sql = mysqli_query($db, "select SUM(tbl_ccp_loans.payableamount) AS total"); 
if ($sql === false) {
    echo 'Error. ' . mysqli_connect_errno() . PHP_EOL;
    exit;
}

$row = mysqli_fetch_assoc($sql); 
$sum = $row['total'];
echo $sum;
?>