However you're building your insert array, you just need to loop through the values and replace any single quotes with two single quotes.
You need to decide how you're going to pragmatically insert your data into the database. Once you've figured that out, post back with what you have, and we'll see what we can do.