Link to home
Start Free TrialLog in
Avatar of lawrence_dev
lawrence_dev

asked on

Transitioning to PDO/MySQL. Need help with CSV import - Pipe delimited

How do I set the delimiter to pipe and use quotes?   I have a field with several commas, so I am changing to pipe delimited.  Each field has quotes as well.

I have tried several different ways to fix.  fgetcsv($handle,""","|",""");




$filename="EP_download.csv";




//open the file
$handle = fopen($filename, "r");
//this is what causes it to skip
fgetcsv($handle,""","|",""");    //How do I set the delimiter to pipe with quotes?



//begin looping through the lines
while (($data = fgetcsv($handle, ""","|",""")) !== FALSE)
{


// loop all column values and escape special characters
 foreach ($data as $key => $value){
  $data[$key] = $value;
}


$statement = $conn->prepare('INSERT IGNORE INTO EPdownload (ID, Title, Category, SubCategory, SubSubCategory, Brand, BrandURL, ProductImage, MSRP, MAPPrice, Description, Specification, DealerCost, PageURL, PageTitle, StartingPageURL, DateTime) VALUES(:ID, :Title, :Category, :SubCategory, :SubSubCategory, :Brand, :BrandURL, :ProductImage, :MSRP, :MAPPrice, :Description, :Specification, :DealerCost, :PageURL, :PageTitle, :StartingPageURL, :DateTime)');

		$params = array(':ID'=>$data[0],
						':Title'=>$data[1],
						':Category'=>$data[2],
						':SubCategory'=>$data[3],
						':SubSubCategory'=>$data[4],
						':Brand'=>$data[5],
						':BrandURL'=>$data[6],
						':ProductImage'=>$data[7],
						':MSRP'=>$data[8],
						':MAPPrice'=>$data[9],
						':Description'=>$data[10],
						':Specification'=>$data[11],
						':DealerCost'=>$data[12],
						':PageURL'=>$data[13],
						':PageTitle'=>$data[14],
						':StartingPageURL'=>$data[15],
						':DateTime'=>$data[16]);
		                $statement->execute($params); 
	
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial