Hi All
Working on a script that imports a large amount of data from a csv file into a database.
However some of the lines in the CSV contain nasty characters which mySQL doesn't like, apostraphes for example.
Can someone recommend a piece of code that can be used to replace these.
I have had a look at a lot of the examples online, however I need to be able to specify multiple rules, ie replace ' with a ft or & with and.
I dont want to use too many loops etc as the data file will have almost 80000 lines when the site goes live and I don't want it to take weeks. At the moment my test file has 7000 lines and it takes 3-4 seconds to process that.
Any advice is greatly appreciated.
Thanks
Aaron
PS - in case it helps, here is the script so far
Working on a script that imports a large amount of data from a csv file into a database.
However some of the lines in the CSV contain nasty characters which mySQL doesn't like, apostraphes for example.
Can someone recommend a piece of code that can be used to replace these.
I have had a look at a lot of the examples online, however I need to be able to specify multiple rules, ie replace ' with a ft or & with and.
I dont want to use too many loops etc as the data file will have almost 80000 lines when the site goes live and I don't want it to take weeks. At the moment my test file has 7000 lines and it takes 3-4 seconds to process that.
Any advice is greatly appreciated.
Thanks
Aaron
PS - in case it helps, here is the script so far
Code:
$file = array();
foreach(file('****.csv') as $line)
{
$file[] = explode(',', $line);
}
foreach($file as $data) {
mysql_select_db($database_wp_master, $wp_master);
$insert*** = "INSERT INTO ***_temp VALUES('$data[12]','$data[13]','$data[11]','$data[15]','$data[9]','$data[3]','$data[20]','$data[21]')";
mysql_query($insert***, $wp_master) or die(mysql_error());
}
echo 'Data Imported<br/><br/>';