Oracle游标查询返回多个记录集如何在zend或php中获取?

时间:2014-02-01 17:14:47

标签: php oracle zend-framework

我从以下oralce select查询中获取记录集时遇到问题:

SELECT ap.PROFILE_FIRST_NAME AS "profileFirstName",
        CURSOR (
                   SELECT ae.EMAIL_ADDRESS AS "emailAddress",
                          ae.EMAIL_ADDRESS_IS_PRIMARY AS "emailAddressIsPrimary"
                      FROM APP_EMAIL_ADDRESS ae
                   WHERE ae.LOGIN_INFO_ID = ap.LOGIN_INFO_ID
               ) as "emails",
        CURSOR(
                 select co.CONTACT_NUMBER AS "contactNumber" 
                 FROM APP_CONTACT co where co.LOGIN_INFO_ID = ap.LOGIN_INFO_ID
               ) as "contacts"   

        FROM APP_PROFILE ap

当我在Toad中执行此查询时,它会按预期返回记录。 每个用户都有多个电子邮件和联系号码。但是当我在Zend中执行此查询时

    $DB = Zend_Registry::get("DB");
    $result = $DB->fetchAll($query);

$ result具有以下值:

Array
(
 [0] => stdClass Object
    (
        [profileFirstName] => 
        [emails] => Resource id #139
        [contacts] => Resource id #140
    )

 [1] => stdClass Object
    (
        [profileFirstName] => Zain
        [emails] => Resource id #141
        [contacts] => Resource id #142
    )
 )

正如我所料,电子邮件应该是2D数组,以包含每个用户的电子邮件,因为联系人应该包含contacts数组。但问题是资源ID#。如何从Resource Id#获取这些值。

最好的问候

1 个答案:

答案 0 :(得分:0)

这是我找到的解决这个问题的方法。

$DB = Zend_Registry::get("DB");
$con = $DB->getConnection();
$stmt = oci_parse($con, $query); // $query can be Resource #id 
oci_execute($stmt);
while ($row = oci_fetch_object($stmt))