PHP Oracle在循环中插入数据的ID不正确

时间:2018-11-12 10:50:59

标签: php oracle loops

我将继续上一个question

现在我需要将值插入数据库。但是插入的ID与我的数据库主数据库上的不正确。

$qModel = oci_parse($c1, "SELECT MODELID, MODEL_NAME FROM WA_LFO_TBL_MODEL 
WHERE ACTIVE = 'Y'");
oci_execute($qModel);
while($dModel = oci_fetch_array($qModel))
{
    $qDtl2 = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_MODEL_CONFIGURATION WHERE MODELID_FK = '" . $dModel['MODELID'] . "'");
    oci_execute($qDtl2);
    while($dDtl2 = oci_fetch_array($qDtl2))
    {
        $q = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_REJECT_PROCESS WHERE MODELID_FK = '" . $dModel['MODELID'] . "' ORDER BY SORT_NO ASC");
        oci_execute($q);
        while($d = oci_fetch_array($q))
        {
            $idkeys[] = $d['RP_ID'];
            $keys[] = $d['RP_NAME'];
        }

        $values = array_fill(0, count($keys), 0);
        $values = array_combine($keys, $values);

        for($i = $readRowAfter; $i < count($linesReject); $i++)
        {
            // if the fileReject is "Tue, Sep 18<tab>2018<tab>23:59:53<tab>"
            $dateobjReject = DateTime::createFromFormat($createFromFormat, $linesReject[$i]);

            // check if date is in your Timespan
            if($dateobjReject < $toDateTime && $dateobjReject > $fromDateTime)
            {
                $rowsintimespanReject++; // count if in timespan

                $lineContent = explode("\t", $linesReject[$i]);

                // loop through line elements and count them
                $x = 0;
                for ($j = 0; $j < count($keys); $j++) {
                    if (!isset($lineContent[$j])) {
                        continue;
                    }

                    // remember position of last not empty column
                    if (trim($lineContent[$j]) != '') {
                        $x = $j;
                    }
                }

                if ($x > 0) {
                    $values[$keys[$x]]++;
                }
            }
        }

        $i = 0; 
        $sql = "";

        foreach ($values as $value)
        {
            if($value != 0)
            {
                $sql = oci_parse($c1,"INSERT INTO WA_LFO_TBL_REJECT_OUTPUT(MODELID_FK, QUANTITY, RPID_FK, CONFIGURATIONID_FK)VALUES('" . $dModel['MODELID'] . "', '" . $value . "', '" . $idkeys[$i] . "', '" . $dDtl2['CONFIGURATIONID'] . "')"); 
                oci_execute($sql);
            } 

            $i++; 
        }
    }
}

如您所见,我正在尝试在foreach函数中插入日期。

但是插入的ID数据不适用于RPID_FK。 我意识到代码可能有问题,试图获取解决方案,但仍然坚持下去。

该代码有问题吗?

0 个答案:

没有答案