这是我的php文件。在该文件中我将数据插入3个表中。当我试图将数据插入bhavcopypc表时,mysql开始跳过在此表中插入数据。 bhavcopypc在此表中有大约900000条记录。如果我有空表而不是正确插入但当该表有更多记录时。那时mysql开始跳过在这个表中插入数据
$smarty = new SmartyWWW();
$filePath = "./bhavcopiesfo";
$handle = '';
$monthOk = '';
$monthInt= '';
$monthIntExp= '';
$expiryDate2 = '';
$expiryDateBc = '';
$generalf_oQuery = "SELECT * FROM generalf_o";
$generalf_oResult = mysql_query($generalf_oQuery);
while($generalf_oRow = mysql_fetch_array($generalf_oResult))
{
$fileName = $generalf_oRow['fileName'];
$year = substr($generalf_oRow['fileName'],7,4);
$month = substr($generalf_oRow['fileName'],4,3);
$date = substr($generalf_oRow['fileName'],2,2);
switch ($month)
{
case "JAN":
$monthOk = '01';
break;
case "FEB":
$monthOk = '02';
break;
case "MAR":
$monthOk = '03';
break;
case "APR":
$monthOk = '04';
break;
case "MAY":
$monthOk = '05';
break;
case "JUN":
$monthOk = '06';
break;
case "JUL":
$monthOk = '07';
break;
case "AUG":
$monthOk = '08';
break;
case "SEP":
$monthOk = '09';
break;
case "OCT":
$monthOk = '10';
break;
case "NOV":
$monthOk = '11';
break;
case "DEC":
$monthOk = '12';
break;
}
$sDate = $year."-".$monthOk."-".$date;
// //Check that data already in bhavcopyf_o table :Start
$storedbhavf_oQuery = "SELECT * FROM storedbhavf_o
WHERE storDate = '".$sDate."'";
$storedbhavf_oResult = mysql_query($storedbhavf_oQuery);
if($storedbhavf_oRow = mysql_fetch_array($storedbhavf_oResult))
{
if($storedbhavf_oRow['status'] == "Ok")
$varStoreBhav = false;
else
{
$varStoreBhav = true;
}
}
else
{
$insertStor = "INSERT INTO storedbhavf_o(storDate,status)
VALUES('".$sDate."','started')";
$insertStorResult = mysql_query($insertStor);
$varStoreBhav = true;
}
//Check that data already in bhavcopyf_o table :End
if($varStoreBhav = true)
{
$row = 0;
$scLineCount = 1;
$FOLineCount = 1;
$NSELineCount = 1;
$handle = fopen($filePath."/".$fileName, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
if($row > 0)
{
$num = count($data);
$exchange = 'F_O';
$expiryDate = $data[2];
$strikePrice = $data[3];
$bhavcopyDate = $data[14];
$contractCode = $data[1];
$openPrice = $data[5];
$highPrice = $data[6];
$lowPrice = $data[7];
$closePrice = $data[8];
$openInterest = $data[12];
$disc207 = strpos($data[2],'-',0);
if($disc207 == 1)
{
$monthStree = substr($data[2],2,3);
}
else if($disc207 == 2)
{
$monthStree = substr($data[2],3,3);
}
else
{
}
$monthStr = $monthStree;
switch ($monthStr)
{
case "Jan":
$monthInt = '01';
break;
case "Feb":
$monthInt = '02';
break;
case "Mar":
$monthInt = '03';
break;
case "Apr":
$monthInt = '04';
break;
case "May":
$monthInt = '05';
break;
case "Jun":
$monthInt = '06';
break;
case "Jul":
$monthInt = '07';
break;
case "Aug":
$monthInt = '08';
break;
case "Sep":
$monthInt = '09';
break;
case "Oct":
$monthInt = '10';
break;
case "Nov":
$monthInt = '11';
break;
case "Dec":
$monthInt = '12';
break;
}
$disc = strpos($data[2],'-',0);
if($disc == 1)
{
$yearDub2 = "20".substr($data[2],8,2);
$expiryDate2 = $yearDub2."-".$monthInt."-0".substr($data[2],0,1);
$expiryDateBc = $yearDub2."".$monthStr."0".substr($data[2],0,1);
}
else if($disc == 2)
{
$yearDub23 = substr($data[2],7,4);
$expiryDate2 = $yearDub23."-".$monthInt."-".substr($data[2],0,2);
$expiryDateBc = $yearDub23."".$monthStr."".substr($data[2],0,2);
}
else
{
}
////////For Expiry:Start
if(strlen(trim($contractCode)) > 0)
{
$disc211 = strpos($data[14],'-',0);
//$pose = strpos($data[14],'-',0) == 1;
if($disc211 == 1)
{
$monthStrExpee = substr($data[14],2,3);
}
else if($disc211 == 2)
{
$monthStrExpee = substr($data[14],3,3);
}
$monthStrExp = $monthStrExpee;
switch ($monthStrExp)
{
case "JAN":
$monthIntExp = '01';
break;
case "FEB":
$monthIntExp = '02';
break;
case "Mar":
$monthIntExp = '03';
break;
case "APR":
$monthIntExp = '04';
break;
case "MAY":
$monthIntExp = '05';
break;
case "JUN":
$monthIntExp = '06';
break;
case "JUL":
$monthIntExp = '07';
break;
case "AUG":
$monthIntExp = '08';
break;
case "SEP":
$monthIntExp = '09';
break;
case "OCT":
$monthIntExp = '10';
break;
case "NOV":
$monthIntExp = '11';
break;
case "DEC":
$monthIntExp = '12';
break;
}
$disc2 = strpos($data[14],'-',0);
//$pose = strpos($data[14],'-',0) == 1;
//echo '<BR>'.substr($data[14],0,1);
if($disc2 == 1)
{
$yearDub = "20".substr($data[14],8,2);
$bhavcopyDate2 = $yearDub."-".$monthIntExp."-0".substr($data[14],0,1);
}
else if($disc2 == 2)
{
$yearDub = substr($data[14],7,4);
$bhavcopyDate2 = $yearDub."-".$monthIntExp."-".substr($data[14],0,2);
}
else
{
}
}
$selectDP = 0;
$noDuplication ="SELECT fileName
FROM duplicate_fo_check
WHERE fileName = '".$fileName."'";
$resultNoDuplicate = mysql_query($noDuplication);
if(mysql_num_rows($resultNoDuplicate) != 0)
{
$selectDP = '1';
}
else
{
$selectDP = '0';
}
if($selectDP == 0)
{
if($data[4] == 'XX')
{
//echo "<br />Insert : ".$row;
$insertData = "INSERT INTO bhavcopyf_o (exchange,bhavcopyDate,contractCode,
expiryDate,expiryDateBc,openPrice,highPrice,lowPrice,closePrice,openInterest)
VALUES ('".$exchange."','".$sDate."','".$contractCode."',
'".$expiryDate2."','".$expiryDateBc."',
".$openPrice.",".$highPrice.",".$lowPrice.",".$closePrice.",".$openInterest.")";
$resultData = mysql_query($insertData);
}
}
$selectDPC = 0;
$noDuplicationPC ="SELECT fileName
FROM duplicate_pc_check
WHERE fileName = '".$fileName."'";
$resultNoPCDuplicate = mysql_query($noDuplicationPC);
if(mysql_num_rows($resultNoPCDuplicate) != 0)
{
$selectDPC = '1';
}
else
{
$selectDPC = '0';
}
if($selectDPC == 0)
{
//echo "<br> ---> ".$data[1];
//echo "<br /> 1 : ".$row." : ".$data[4];
if(($data[4] == 'CE' || $data[4] == 'PE'))
{
//echo "<br /> 2 ";
if($data[4] == 'CE')
{
$putCall = 'C';
}
elseif($data[4] == 'PE')
{
$putCall = 'P';
}
else
{
$putCall = '';
}
if($openInterest > 0)
{
$insertData = "INSERT INTO bhavcopypc (exchange,bhavcopyDate,contractCode,strikePrice,
expiryDate,expiryDateBc,openPrice,highPrice,lowPrice,closePrice,
openInterest,putCall)
VALUES ('".$exchange."','".$sDate."','".$contractCode."',".$strikePrice.",
'".$expiryDate2."','".$expiryDateBc."',
".$openPrice.",".$highPrice.",".$lowPrice.",
".$closePrice.",".$openInterest.",'".$putCall."')";
$resultDataRes = mysql_query($insertData);
if($resultDataRes)
{
$selectPutCall = "SELECT expiryDate,contractCode,bhavcopyDate,
SUM(openInterest) AS openInterest,
putCall
FROM bhavcopypc
WHERE bhavcopyDate = '".$sDate."'
AND expiryDate = '".$expiryDate2."'
AND contractCode = '".$contractCode."'
AND putCall = '".$putCall."'
GROUP BY contractCode,expiryDate,bhavcopyDate,putCall";
$selectPutCallRes = mysql_query($selectPutCall);
if($pcRow = mysql_fetch_array($selectPutCallRes))
{
$expiryDateSelect = $pcRow['expiryDate'];
$contractCodeSelect = $pcRow['contractCode'];
$bhavcopyDateSelect = $pcRow['bhavcopyDate'];
$openInterestSelect = $pcRow['openInterest'];
$putCallSelect = $pcRow['putCall'];
$query1 = "DELETE FROM bhavcopypcoi
WHERE bhavcopyDate = '".$sDate."'
AND expiryDate = '".$expiryDate2."'
AND contractCode = '".$contractCode."'
AND putCall = '".$putCall."'";
$result1=mysql_query($query1);
if(!$result1)
echo "DELETING FAILED";
$insertNewOi = "INSERT INTO bhavcopypcoi (contractCode,expiryDate,bhavcopyDate,openInterest,putCall)
VALUES('".$contractCodeSelect."','".$expiryDateSelect."',
'".$bhavcopyDateSelect."','".$openInterestSelect."','".$putCallSelect."')";
$insertNewOiRes = mysql_query($insertNewOi);
if(!$insertNewOiRes)
{
}
}
}
}
}
}
/////////////////// Put Call Data Insert End //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
$row++;
}
$selectChk = 0;
$noDuplicationChk ="SELECT fileName
FROM duplicate_fo_check
WHERE fileName = '".$fileName."'";
$resultNoChkDuplicate = mysql_query($noDuplicationChk);
if(mysql_num_rows($resultNoChkDuplicate) != 0)
{
$selectChk = '1';
}
else
{
$selectChk = '0';
}
if($selectChk == 0)
{
$insertDPC = "INSERT INTO duplicate_fo_check (fileName)
VALUES ('".$fileName."')";
$resultDPC = mysql_query($insertDPC);
}
$selectChkPc = 0;
$noDuplicationChkPc ="SELECT fileName
FROM duplicate_pc_check
WHERE fileName = '".$fileName."'";
$resultNoChkPcDuplicate = mysql_query($noDuplicationChkPc);
if(mysql_num_rows($resultNoChkPcDuplicate) != 0)
{
$selectChkPc = '1';
}
else
{
$selectChkPc = '0';
}
if($selectChkPc == 0)
{
$insertDPCPC = "INSERT INTO duplicate_pc_check (fileName)
VALUES ('".$fileName."')";
$resultDPCPC = mysql_query($insertDPCPC);
}
fclose($handle);
}
header("Location: ./txtFileF_OAmit.php");
}
?>