rgb192
asked on
sometimes this file runs, other times it crashes fastcgi
I have tried running using commandline, codeeditor, and browser
sometimes where I run this one php file I get error
fastcgi/cgi stopped working
Fault Module Version: 5.2.6.6
Fault Module Timestamp: 481b9057
Exception Code: c0000005
Exception Offset: 00005948
OS Version: 6.0.6002.2.2.0.1296.17
Locale ID: 1033
Additional Information 1: fd00
Additional Information 2: ea6f5fe8924aaa756324d57f87
Additional Information 3: fd00
Additional Information 4: ea6f5fe8924aaa756324d57f87
<?php
require_once('../common.php');
$dir="D:/Files";
$files = scandir($dir, 1);
foreach ($files as $f){
$string=$f;
$string = str_replace(".txt", "", $string);
$parts = explode("_", $string);
$data=file("$dir/$f");
unset($data[0]);
foreach($data as $v){
$v=explode("\t",$v);
$nb = count($v);
if ($nb>48){
$nb=48;
}
if($parts[1]=='FBA'){
$sql="
insert into af(country,fulfilled,amazonorderid,merchantorderid,shipmentid,shipmentitemid,amazonorderitemid,merchantorderitemid,purchasedate,paymentsdate,shipmentdate,reportingdate,buyeremail,buyername,buyerphonenumber,sku,productname,quantityshipped,currency,itemprice,itemtax,shippingprice,shippingtax,giftwrapprice,giftwraptax,shipservicelevel,recipientname,shipaddress1,shipaddress2,shipaddress3,shipcity,shipstate,shippostalcode,shipcountry,shipphonenumber,billaddress1,billaddress2,billaddress3,billcity,billstate,billpostalcode,billcountry,itempromotiondiscount,shippromotiondiscount,carrier,trackingnumber,estimatedarrivaldate,fulfillmentcenterid,fulfillmentchannel,saleschannel ) select
";
}else if ($parts[1]=='FBM'){
$sql="
insert into am(country,fulfilled,orderid,orderitemid,purchasedate,paymentsdate,buyeremail,buyername,buyerphonenumber,sku,productname,quantitypurchased,currency,itemprice,itemtax,shippingprice,shippingtax,shipservicelevel,recipientname,shipaddress1,shipaddress2,shipaddress3,shipcity,shipstate,shippostalcode,shipcountry,shipphonenumber,deliverystartdate,deliveryenddate,deliverytimezone,deliveryinstructions ) select
";
}
$sql.= "'{$parts[2]}','{$parts[1]}',";
for ($x=0;$x<$nb;$x++){
$sql.= "'{$v[$x]}',";
}
$sql=substr($sql, 0, strlen($sql)-1);
if($parts[1]=='FBA'){
$sql.="where not exists (select null from af where amazonorderid = '{$v[0]}')";
}else if($parts[1]=='FBM'){
$sql.="where not exists (select null from am where orderid = '{$v[0]}')";
}
echo '<br>'.$sql;
dbquery2($sql);
} //end foreach data
}//end foreachfiles
dbquery("
insert into a (saleschannel,fulfilmentchannel,orderdate,orderid,qty,sku,contactbuyer,productdetails, totalprice)
select country,fulfilled,purchasedate,amazonorderid,quantityshipped,sku,buyername,productname,
case when isnumeric(af.quantityshipped)=1 then CAST(af.quantityshipped as decimal(18,2)) else 0 end
* case when isnumeric(af.itemprice)=1 then CAST(af.itemprice as decimal(18,2)) else 0 end
+ case when isnumeric(af.itemtax)=1 then CAST(af.itemtax as decimal(18,2)) else 0 end
+ case when isnumeric(af.shippingprice)=1 then CAST(af.shippingprice as decimal(18,2)) else 0 end
+ case when isnumeric(af.shippingtax)=1 then CAST(af.shippingtax as decimal(18,2)) else 0 end
+ case when isnumeric(af.giftwrapprice)=1 then CAST(af.giftwrapprice as decimal(18,2)) else 0 end
+ case when isnumeric(af.giftwraptax)=1 then CAST(af.giftwraptax as decimal(18,2)) else 0 end
from af
where
af.merchantorderid=''
and
not exists (select 1 from a where a.orderid = af.amazonorderid )
");
dbquery("
insert into a (saleschannel,fulfilmentchannel,orderdate,orderid,qty,sku,contactbuyer,productdetails, totalprice)
select country,fulfilled,shipmentdate,amazonorderid,quantityshipped,sku,buyername,productname,
case when isnumeric(af.quantityshipped)=1 then CAST(af.quantityshipped as decimal(18,2)) else 0 end
* case when isnumeric(af.itemprice)=1 then CAST(af.itemprice as decimal(18,2)) else 0 end
+ case when isnumeric(af.itemtax)=1 then CAST(af.itemtax as decimal(18,2)) else 0 end
+ case when isnumeric(af.shippingprice)=1 then CAST(af.shippingprice as decimal(18,2)) else 0 end
+ case when isnumeric(af.shippingtax)=1 then CAST(af.shippingtax as decimal(18,2)) else 0 end
+ case when isnumeric(af.giftwrapprice)=1 then CAST(af.giftwrapprice as decimal(18,2)) else 0 end
+ case when isnumeric(af.giftwraptax)=1 then CAST(af.giftwraptax as decimal(18,2)) else 0 end
from af
where
af.merchantorderid!=''
and
not exists (select 1 from a where a.orderid = af.amazonorderid )
");
dbquery("
insert into a (saleschannel,fulfilmentchannel,orderdate,orderid,qty,sku,contactbuyer,productdetails, totalprice)
select country,fulfilled,purchasedate,orderid,quantitypurchased,sku,buyername,productname,
case when isnumeric(am.quantitypurchased)=1 then CAST(am.quantitypurchased as decimal(18,2)) else 0 end
* case when isnumeric(am.itemprice)=1 then CAST(am.itemprice as decimal(18,2)) else 0 end
+ case when isnumeric(am.itemtax)=1 then CAST(am.itemtax as decimal(18,2)) else 0 end
+ case when isnumeric(am.shippingprice)=1 then CAST(am.shippingprice as decimal(18,2)) else 0 end
+ case when isnumeric(am.shippingtax)=1 then CAST(am.shippingtax as decimal(18,2)) else 0 end
from am
where
not exists (select 1 from a where a.orderid = am.orderid )
");
dbquery("update a set orderdate=convert(varchar(10),orderdate,120)");
dbquery("update a set fulfilmentchannel='Amazon' where fulfilmentchannel='FBA'");
dbquery("update a set fulfilmentchannel='Merchant' where fulfilmentchannel='FBM'");
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER