1

我正在使用 oracle 适配器连接到数据库,这是 application.ini 中的配置,

resources.db.adapter = "Oracle"
resources.db.params.host = "localhost"
resources.db.params.username = "user"
resources.db.params.password = "2012"
resources.db.params.dbname = "books"
resources.db.isDefaultTableAdapter = true

在这里我如何调用存储过程

   $db = Zend_Db_Table::getDefaultAdapter();
   try {
        //    $sql = "select * from dual";
        $sql = "begin BA_OPERATIONS_PKG.GETMEMBERCRED(" .
                ":I_USER_ID, :DATA_REC); end;";

        $statement = new Zend_Db_Statement_Oracle($db, $sql);

        $params = array(
            'I_USER_ID' => $userId
        );

        // Create a cursor
        $cursor = new Zend_Db_Cursor_Oracle($db);

        // Bind the cursor as a parameter. This SHOULD push a new cursor in the
        // $_bindCursor stack from Zend_Db_Statement.
        $statement->bindCursor('DATA_REC', $cursor);

         $statement->execute($params);

        echo $cursor;

    } catch (Exception $e) {
        print_r($e->getMessage());
    }

这是我的例外

  include_once(Zend\Db\Cursor\Oracle.php) [function.include-once]: failed to open stream: No such file or directory in D:\ZendFramework\library\Zend\Loader.php 
4

1 回答 1

0

我扩展了oracle适配器并添加了一个方法:

<?php

/**
 * @see Zend_Db_Adapter_Pdo_Oci
 */
require_once 'Zend/Db/Adapter/Oracle.php';

class Zend_Db_Adapter_Cds extends Zend_Db_Adapter_Oracle
{
    public function fetchCursor($sql, $bind = array())
    {
        $data = array();
        $conn = $this->getConnection();

        $curs = oci_new_cursor($conn);
        $stmt = oci_parse($conn, $sql);

        oci_bind_by_name($stmt, "cursor", $curs, -1, OCI_B_CURSOR);
        foreach ($bind as $key => &$val) {
            oci_bind_by_name($stmt, $key, $val, -1, OCI_ASSOC);
        }

        oci_execute($stmt);
        if ($e = oci_error($stmt)) {
            throw new Zend_Db_Adapter_Oracle_Exception($e, -1234);
        }

        oci_execute($curs);
        if (oci_fetch_all($curs, $data, 0, -1, OCI_FETCHSTATEMENT_BY_ROW)) {
            ;//var_dump($data);
        }

        oci_free_statement($stmt);
        oci_free_statement($curs);

        return $data;
    }
}
于 2014-08-20T13:43:20.290 回答