【问题标题】:Calling Oracle Query Using PHP Function with constructor使用带有构造函数的 PHP 函数调用 Oracle 查询
【发布时间】:2026-02-01 01:55:01
【问题描述】:

我不知道我的错误在哪里,但我想将一个 oracle 查询存储在一个函数中并将该函数返回到一个数组中。

JobDrop.php

class JobDrop {
    private $jobSql = "SELECT VMI.PROJECT_NO JOB FROM VW_MTO_INFO VMI ORDER BY VMI.PROJECT_NO ASC";

    function _construct($jobSql){
        $this->jobSql = $jobSql;
    }

    function JobDropdown($conn){
        $jobParse = oci_parse($conn, $this->jobSql);
        $jobExcErr = oci_execute($jobParse);

        if (!$jobExcErr){
            $e = oci_error($jobParse);
                print htmlentities($e['message']);
                print "\n<pre>\n";
                print htmlentities($e['sqltext']);
                printf("\n%".($e['offset']+1)."s", "^");
                print  "\n</pre>\n";
        } else {

            $res = array();
            while ($row = oci_fetch_assoc($jobParse)){
                $res[] = $row;
            } 
            $listVendor = json_encode($res, JSON_PRETTY_PRINT);

            return $listVendor;
        }


}
    }

在test.php中

include './job_drop.php';
require_once('../../lib/dbinfo.inc.php');
$conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);


$jobdrop = new JobDrop();

$jobdrop->JobDropdown($conn);
var_dump($jobdrop);

但它不显示浏览器内的数组。而是显示查询字符串,

object(JobDrop)#1 (1) { ["jobSql":"JobDrop":private]=> string(74) "SELECT VMI.PROJECT_NO JOB FROM VW_MTO_INFO VMI ORDER BY VMI.PROJECT_NO ASC" } 

请帮助我在这里做错了什么

【问题讨论】:

  • 您是说要将查询结果保存在 JobDrop 类中吗?正如你现在所拥有的,你没有捕获 JobDropdown 函数的返回值。

标签: javascript php sql oracle


【解决方案1】:

如果您想查看数组,请执行以下操作:

$res = $jobdrop->JobDropdown($conn);
var_dump($res);

【讨论】:

  • 这没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
  • @IanKemp:作者的帖子将but it doesnt show the array inside the browser. it shows the query string instead 标识为请求帮助的最近问题。我的回答解决了这个问题。