我非常感谢有人帮助解决问题。
顺便问一下我在马盖托
我有这种方法,它基本上需要两组数据并用它们创建一个sql语句。

private function _getInsertSql($data, $itemData)
{

    $sql = 'insert into orders_headers (';
    $keys = array_keys($data);
    $sql .= implode(', ', $keys);
    $sql .= ') values (';
    foreach($data as $value) {
        $type = $value['type'];
        $vv = $value['value'];
        if ($type == 'number') {
            $sql .= $vv;
        } else {
            $sql .= $this->_db->quote($vv);
        }
        $sql .= ',';
    }
    $sql = substr($sql, 0, strlen($sql)-1);
    $sql .= ');';

    $first = 0;
    $sql .= 'insert into orders_lines (';
    foreach($itemData as $data) {
        if ($first <= 0) {
            $keys = array_keys($data);
            $sql .= implode(', ', $keys);
            $sql .= ') values (';
        } else {
            $sql .= '(';
        }
        foreach($data as $value) {
            $type = $value['type'];
            $vv = $value['value'];
            if ($type == 'number') {
                $sql .= $vv;
            } else {
                $sql .= $this->_db->quote($vv);
            }
            $sql .= ',';
        }
        $sql = substr($sql, 0, strlen($sql)-1);
        $sql .= '),';
        $first++;
    }

    $sql = substr($sql, 0, strlen($sql)-1);

    $sql .= ';';
    Mage::log("START" .$sql . "END", NULL, 'sql.log');
    return $sql;
}


正如您最终看到的那样,我注销了.sql,奇怪的是它两次生成相同的查询。因此,在数据库中两次插入同一行。

我一生都看不到它循环到顶部并再次创建查询的位置。

输出sql是:

2013-06-11T15:37:45 + 00:00调试(7):开始插入orders_header(orderID,日期时间,ip,customerID,姓氏,姓氏,地址1,地址2,镇,县,国家,邮政编码,电话,传真,电子邮件,公司,deliveryName,deliveryAddress1,deliveryAddress2,deliveryTown,deliveryCounty,deliveryCountry,deliveryPostcode,deliveryTelephone,goodsTotal,shippingTotal,taxTotal,discountTotal,order_state,order_status,order_comments,order_save_time,状态,shippingMethod,paymentID,paymentName,paymentDate,shippingID,orderNotes, PaymentNameNative,shippingMethodNative,referURL,accTypeID,offerCode,randID,e_website,e_status,e_purchaseordref,e_statuschk,e_accepted值('100004952','20130611153744','127.0.0.1',0,'TES','S','S ','','S','','GB','S','SA','','[email protected]','','TES S','S','', 'S','','GB','S','SA',28.88,7.25,4.81,0,'new','pending_awaiting_payment','','20130611153745','P','udropship_default', 5,'支票','',0,'','支票','udropship_default','主/站点/',0,'','100004 952','master / site /','ZZZ888','','2106','');插入xm1_orders_lines(orderID,productID,代码,名称,数量,重量,价格,名称本机,税额,ooprice,ootaxamount ,SupplierID,SupplierCost,SupplierCostCurrencyID,order_state,order_status,order_save_time)值('100004952',2106,'UGWA050','Stainless Steelwine冰桶,万能9 pt',1,10.0900,16.82,'Stainless Steelwine冰桶,万能9 pt',3.36,0,0,5,10.0900,1,'new','pending_awaiting_payment','20130611153745'); END
2013-06-11T15:37:45 + 00:00调试(7):开始插入orders_header(orderID,日期时间,ip,customerID,姓氏,姓氏,地址1,地址2,镇,县,国家,邮政编码,电话,传真,电子邮件,公司,deliveryName,deliveryAddress1,deliveryAddress2,deliveryTown,deliveryCounty,deliveryCountry,deliveryPostcode,deliveryTelephone,goodsTotal,shippingTotal,taxTotal,discountTotal,order_state,order_status,order_comments,order_save_time,状态,shippingMethod,paymentID,paymentName,paymentDate,shippingID,orderNotes, PaymentNameNative,shippingMethodNative,referURL,accTypeID,offerCode,randID,e_website,e_status,e_purchaseordref,e_statuschk,e_accepted值('100004952','20130611153744','127.0.0.1',0,'TES','S','S ','','S','','GB','S','SA','','[email protected]','','TES S','S','', 'S','','GB','S','SA',28.88,7.25,4.81,0,'new','pending_awaiting_payment','','20130611153745','P','udropship_default', 5,'支票','',0,'','支票','udropship_default','主/站点/',0,'','100004 952','/ master / site /','ZZZ888','','2106','');插入xm1_orders_lines(订单ID,产品ID,代码,名称,数量,重量,价格,名称本机,税额,单价, ootaxamount,supplierID,supplierCost,supplierCostCurrencyID,order_state,order_status,order_save_time)值('100004952',2106,'UGWA050','Stainless Steelwine冰桶,万能9 pt',1,10.0900,16.82,'Stainless Steelwine冰桶,magnum 9 pt',3.36,0,0,5,10.0900,1,'new','pending_awaiting_payment','20130611153745'); END

谁能提供帮助?

谢谢

最佳答案

我认为foreach不会给您两次查询,但是您的方法被两次调用。您代码中的log方法在foreach循环之外,并且日志文件本身包含2个条目(用START和END包装)。
更好地找出要在哪里调用该方法并在那里进行调试。

10-06 00:39