Hi everyone
I have a csv file with data such as first name, surname, tel etc and I'd like to populate a table inside my MySQL database automatically.
So far I have this but I keep getting an access denied error and I don't know why:
<?php
$server = 'localhost';
$user = 'username';
$password = 'password';
// open connection to MySQL server
$connection = mysql_connect($server,$user,$password)
or die ('Unable to connect!');
//select database
mysql_select_db('table_name') or die ('Unable to select database!');
// clear the table down
$sql = "TRUNCATE TABLE table_name";
// run the first query to clear table
mysql_query($sql) or die(mysql_error());
// set up query to import data, assuming the
// csv file is at the top level of the C drive
$sql = "LOAD DATA INFILE 'users.txt'
INTO TABLE table_name
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n'";
// run the query to load the data
mysql_query($sql) or die(mysql_error());
?>
Any help would be greatly appreciated. Virtual cookies are up for grabs as a reward ;)