Hi,
I'm trying to import a CSV (tab) delimited file into a MySQL database, however it error's when importing fields with an apostrophe.
I'm importing the data using the fgetcsv function:
$filename='$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE)
{
if (strlen($data[0])== 1) {
$import="INSERT into data(type, timestamp, program_id, id, element_id, event_id, referrer, visitor, user_agent, user_id, order_number, order_value, currency, lead, click_to, invalid, epi, epi2, quantity, pool_id, report, query) values('$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[11]', '$data[12]', '$data[13]', '$data[14]', '$data[15]', '$data[16]', '$data[17]', '$data[18]', '$data[19]', '$data[20]', '$data[21]')";
$result = mysql_query($import);
if (!$result){ $error = mysql_error();
echo $error; }
}
}
I've attempted to use the str_replace but this returns, the below errors:
Notice: Undefined offset: 18 in C:\wamp\ on line 20
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\ on line 20
What's the best way to escape these characters when they are in an array.
Thanks in advance.
I'm trying to import a CSV (tab) delimited file into a MySQL database, however it error's when importing fields with an apostrophe.
I'm importing the data using the fgetcsv function:
$filename='$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE)
{
if (strlen($data[0])== 1) {
$import="INSERT into data(type, timestamp, program_id, id, element_id, event_id, referrer, visitor, user_agent, user_id, order_number, order_value, currency, lead, click_to, invalid, epi, epi2, quantity, pool_id, report, query) values('$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[11]', '$data[12]', '$data[13]', '$data[14]', '$data[15]', '$data[16]', '$data[17]', '$data[18]', '$data[19]', '$data[20]', '$data[21]')";
$result = mysql_query($import);
if (!$result){ $error = mysql_error();
echo $error; }
}
}
I've attempted to use the str_replace but this returns, the below errors:
Notice: Undefined offset: 18 in C:\wamp\ on line 20
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\ on line 20
What's the best way to escape these characters when they are in an array.
Thanks in advance.