使用PHP函数调用Oracle查询与构造函数

时间:2015-10-26 04:40:14

标签: javascript php sql oracle

我不知道我的错误在哪里,但我想在函数中存储一个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" } 

请帮助我在这里做错了

1 个答案:

答案 0 :(得分:1)

如果要查看数组,请执行:

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