从Oracle查询PHP中列的总和

时间:2014-06-14 05:45:29

标签: php sql oracle

这个问题有点像新手,但我正在学习数据库。

所以我要查询一个列的总数,我想在PHP中显示它

$sumSql = "select sum(weight) as total_sum from master_drawing";

$sumParse = oci_parse($conn, $sumSql);

oci_bind_by_name($sumParse, "total_sum", $total);

oci_execute($sumParse);

while(oci_fetch($sumParse)){
    echo $total;
}

但不知何故,错误是这样的:

警告:oci_bind_by_name():ORA-01036:第30行的C:\ xampp \ htdocs \ WeltesInformationCenter \ newEmptyPHP.php中的非法变量名称/编号

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

$sumSql = "select sum(weight) as total_sum from master_drawing";

$sumParse = oci_parse($conn, $sumSql);

oci_define_by_name($sumParse, "TOTAL_SUM", $total);

oci_execute($sumParse);

while(oci_fetch($sumParse)){
    echo $total;
}

您必须始终使用,oci_define_by_name和列名称。