| | |
Populating a MySQL table with data from a csv file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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:
Any help would be greatly appreciated. Virtual cookies are up for grabs as a reward
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 Syntax (Toggle Plain Text)
<?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
This user has a spatula. We don't know why, but we are afraid.
Your code works fine on my computer. You are probably getting 'access denied' because you don't have enough privileges for the mysql user. Use grant to grant permissions for the users.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
•
•
Your code works fine on my computer. You are probably getting 'access denied' because you don't have enough privileges for the mysql user. Use grant to grant permissions for the users.
This user has a spatula. We don't know why, but we are afraid.
Ok, it can't be grant access because I'm using administrator. I thought it might be my windows firewall preventing access but I've turned it off and I'm still getting the access denied error. Are there any other possibilities?
I've tried this on 2 separate servers not associated with one another at all and I'm getting the same access denied error.
I've tried this on 2 separate servers not associated with one another at all and I'm getting the same access denied error.
This user has a spatula. We don't know why, but we are afraid.
•
•
•
•
Ok, it can't be grant access because I'm using administrator. I thought it might be my windows firewall preventing access but I've turned it off and I'm still getting the access denied error. Are there any other possibilities?
I've tried this on 2 separate servers not associated with one another at all and I'm getting the same access denied error.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Other Threads in the PHP Forum
- Previous Thread: Displaying images from mysql database
- Next Thread: loop array insert into database
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube






