繁体   English   中英

尝试使用zend框架连接到数据库时出错

[英]Error while trying to connect to DB using zend framework

我正在使用oracle适配器建立与db的连接,这是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 

我扩展了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;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM