Transitioning to PDO/MySQL. Need help with CSV import error

I have worked this many ways.  I am getting the following errors:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Option) VALUES('02802', 'Color', 'Blue', '')'

PDOStatement->execute(Array) #1 {main} thrown

Data looks  like this:



//open the file
$handle = fopen($filename, "r");
//this is what causes it to skip

//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 options (ParentSKU, SKU, Choice, Option) VALUES(:ParentSKU, :SKU, :Choice, :Option)');

		$params = array(":ParentSKU" => isset($data[0])?$data[0]:"",
						":SKU" => isset($data[1])?$data[1]:"",
						":Choice" => isset($data[2])?$data[2]:"",
						":Option" => isset($data[3])?$data[3]:"");
echo $data[0]."&nbsp;".$data[1]."&nbsp;".$data[2]."&nbsp;".$data[3]."<BR>";

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PDO and prepared statements wouldn't give you this error as the values are not part of the sql.

right syntax to use near 'Option) VALUES('02802', 'Color', 'Blue', '')'

Open in new window

So are you sure the error is not coming from somewhere else?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lawrence_devAuthor Commented:
Thanks for your help Gary!!

Actually, 'Option' is a reserved word and cannot be used.  I changed it to 'Opt' and it worked fine.
lawrence_devAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.