<?php

$destination_file 
"4742.txt";
$sasid "sas_id"// REPLACE sas_id with your SAS ID; Can be found at the top of any SAS page

// The following variables make the connection to your database

$dbuser "db_username"// REPLACE db_user with the username used to connect to your database
$dbpass "db_password"// REPLACE db_pass with the password used to connect to your database
$database "database"// REPLACE database with the name of your database

// The following two variables will be the names of the table(s) in your database
// MAKE SURE THE NAMES YOU CHOOSE DO NOT ALREADY EXIST. THEY WILL BE DROPPED.

$temptable "naturehills_temp";
$maintable "naturehills";

$datafeed file_get_contents($destination_file);
$fp fopen($destination_file"w");
$replace str_replace("YOURUSERID",$sasid,$datafeed);
fwrite($fp$replace);
fclose($fp);

mysql_pconnect("localhost",$dbuser,$dbpass);
mysql_select_db($database);

$FeedFile $destination_file;

mysql_query("drop table $temptable");

mysql_query("CREATE TABLE $temptable (ProductID int(11) NOT NULL default '0',Name varchar(255) NOT NULL default '',MerchantID varchar(50) NOT NULL default '',Merchant varchar(50) NOT NULL default '',Link text NOT NULL,Thumbnail text NOT NULL,BigImage text NOT NULL,Price varchar(50) NOT NULL default '',RetailPrice varchar(50) NOT NULL default '',Category varchar(50) NOT NULL default '',SubCategory varchar(50) NOT NULL default '',Description longtext NOT NULL,Custom1 text NOT NULL,Custom2 text NOT NULL,Custom3 text NOT NULL,Custom4 text NOT NULL,Custom5 text NOT NULL,LastUpdated varchar(100) NOT NULL default '',status varchar(50) NOT NULL default '', PRIMARY KEY (ProductID))") or die(mysql_error());

$feed fopen($FeedFile'r');
$rowNum 0;

while(
$data fgetcsv($feed50000"|")){

   
$ProductID addslashes($data[0]);
   
$word $data[1];
   
$word preg_replace("/[^a-zA-Z0-9s]/"" "$word);
   
$word preg_replace("/\s+/"" "$word);
   
$word ucwords(strtolower($word));
   
$MerchantID addslashes($data[2]);
   
$Merchant addslashes($data[3]);
   
$Link addslashes($data[4]);
   
$Thumbnail addslashes($data[5]);
   
$BigImage addslashes($data[6]);
   
$Price addslashes($data[7]);
   
$RetailPrice addslashes($data[8]);
   
$Category addslashes($data[9]);
   
$SubCategory addslashes($data[10]);
   
$Description addslashes($data[11]);
   
$Custom1 addslashes($data[12]);
   
$Custom2 addslashes($data[13]);
   
$Custom3 addslashes($data[14]);
   
$Custom4 addslashes($data[15]);
   
$Custom5 addslashes($data[16]);
   
$LastUpdated addslashes($data[17]);
   
$status addslashes($data[18]);

   
$sql mysql_query("insert into $temptable (ProductID, Name, MerchantID, Merchant, Link, Thumbnail, BigImage, Price, RetailPrice, Category, SubCategory, Description, Custom1, Custom2, Custom3, Custom4, Custom5, LastUpdated, status) values ('$ProductID', '$Name', '$MerchantID', '$Merchant', '$Link', '$Thumbnail', '$BigImage', '$Price', '$RetailPrice', '$Category', '$SubCategory', '$Description', '$Custom1', '$Custom2', '$Custom3', '$Custom4', '$Custom5', '$LastUpdated', '$status')") or die(mysql_error());
   
$rowNum++;
}

mysql_query("drop table $maintable");
mysql_query("ALTER TABLE $temptable RENAME $maintable") or die(mysql_error());
fclose($feed);

?>