Php magento在不丢失数组值的情况下建立多个数据库连接

Php magento在不丢失数组值的情况下建立多个数据库连接,php,mysql,arrays,zend-framework,magento,Php,Mysql,Arrays,Zend Framework,Magento,我正在尝试连接到两个不同的数据库,所以我的脚本应该如下所示 $conn = Mage::getSingleton('core/resource')->getConnection('core_write'); $result = $conn->query('select * from sales_flat_order WHERE customer_id='.$session->getCustomerId().' AND state="complete" A

我正在尝试连接到两个不同的数据库,所以我的脚本应该如下所示

        $conn = Mage::getSingleton('core/resource')->getConnection('core_write');
    $result = $conn->query('select * from sales_flat_order WHERE customer_id='.$session->getCustomerId().' AND state="complete" AND is_virtual=1 AND juno_order_id!="null"');

    $orderIds=array();

    foreach ($result as $orderId)
    {
    $orderIds[]=$orderId[entity_id];    

    $itemsonOrder=$conn->query('select * from sales_flat_order_items WHERE order_id='.$order[entity_id]);



    }



// value of first array $orderIds gets lost if i make annother connection using $conn
        echo 'items on order';
        print_r($itemsonOrder);
        echo '<pre>';
        print_r($orderIds);
        echo '</pre>';
查找当前登录客户的所有订单,其中订单状态为“完成”,它是虚拟产品,并且具有juno订单id。此查询工作正常

收集所有已找到的订单ID,并将它们存储在一个数组中。这样做很好

现在连接到sales_order_items,并针对订单id中的每个项目检查数据库是否有url下载链接

如果没有,我将连接到api-

问题是,当我想建立第二个连接时,我似乎丢失了$orderIds数组中存储的所有值

我一直在寻找解决方案,但我对zend框架还是相当陌生的

任何帮助都将不胜感激

我的剧本如下

        $conn = Mage::getSingleton('core/resource')->getConnection('core_write');
    $result = $conn->query('select * from sales_flat_order WHERE customer_id='.$session->getCustomerId().' AND state="complete" AND is_virtual=1 AND juno_order_id!="null"');

    $orderIds=array();

    foreach ($result as $orderId)
    {
    $orderIds[]=$orderId[entity_id];    

    $itemsonOrder=$conn->query('select * from sales_flat_order_items WHERE order_id='.$order[entity_id]);



    }



// value of first array $orderIds gets lost if i make annother connection using $conn
        echo 'items on order';
        print_r($itemsonOrder);
        echo '<pre>';
        print_r($orderIds);
        echo '</pre>';

当您连接第二个查询时,您还没有完成第一个查询。继续并完成第一个查询,然后开始第二个查询。试试这样的东西

$conn->query('select * from sales_flat_order_items WHERE order_id='.$orderId);
此外,您可能应该确保在执行查询时使用参数。像这样连接sql字符串可能会很危险,有时会导致漏洞。比如说,

$conn->query('select * from sales_flat_order_items WHERE order_id=?', array($orderId));
应改为


另外,您真的需要选择*???我的意思是,只需选择您需要的列。

您的意思是,您正在尝试实例化连接,而它将获得默认的null。。。正在中使用的数据库在app/etc/local.xml中定义。。。我认为这是OOP的基本问题。