【问题标题】:Querying total sum of a column in PHP from Oracle从 Oracle 查询 PHP 中某列的总和
【发布时间】:2014-06-14 14:09:24
【问题描述】:

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

所以我正在查询一列的总数,我想在 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:C:\xampp\htdocs\WeltesInformationCenter\newEmptyPHP.php 第 30 行中的非法变量名称/编号

我在这里做错了什么?

【问题讨论】:

    标签: php sql oracle


    【解决方案1】:
    $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,并且列名始终使用大写字母。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 2022-11-25
      • 2020-01-05
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多