1

I'm very new to PHP, with basic understanding. However I am in need of being able to pass data from a text file to a mysql database.

The text file contains all the data I need, and it is all tab separated and on separate rows for separate entries, so 24 columns and the data is in the same order on each row.(sorry for stating obvious, but want to be clear to get best answer fast) I need all the data importing, so no specific rows or columns. I have already made the database structure using phpmMyAdmin. So it is a table in a database, one thing I've noticed is that the code I've found never specifies the database and the table, either one or the other, this confuses me.

It is just needed for a localhost server running xampp.

I've been searching for ways for the last 2 days I have found many results, but most are very specific to the individual, or have extra code for queries n' such and with my limited understanding right now it makes it hard to filter out what I need.

The first thing I found was

LOAD DATA INFILE '/tmp/exampleFile.txt' INTO TABLE TableExample;

Which with to me seems to good to be true, but sadly this didn't work, I simply got the error: "Parse error: syntax error, unexpected 'DATA' (T_STRING)"

I'm sure this has been answered as simply as I am asking now somewhere but in my current tired state I have not found it.

zavg
  • 10,351
  • 4
  • 44
  • 67
Vereonix
  • 1,341
  • 5
  • 27
  • 54
  • I get the same error: "Parse error: syntax error, unexpected 'DATA' (T_STRING) in C:\xampp\htdocs\UniProject\orderstodb.php on line 2", code now being LOAD DATA INFILE "amazonoutput.txt" INTO TABLE orders FIELDS TERMINATED BY '\t'; I've tried with the path and just the file name as the php file is in same location. I've seen posted other methods where you need to have the php sign into the database with username password etc, not sure if relevant. ok just thought, and this will either way make me seem stupid, but this code isn't php is it? its sql, or am I just too tired. – Vereonix Oct 12 '13 at 20:04
  • This is where you'll tell me to go home for being too much of a noob, but I'm not sure what you mean by command line? My initial thought is open cmd but thats not right. – Vereonix Oct 12 '13 at 20:09
  • Will I need to do something such as $import = mysql_query(the code I last posted); or something to that effect, my uni course has dropped us all in php and mysql so right now they're kinda blurring, as we haven't touched mysql properly yet – Vereonix Oct 12 '13 at 20:12
  • if I remove the password entirely it gives the same error of "(using password: NO)" It connects when I use my mysql password, but the root user that has access or the database has no password apparently. So its like I need the mysql pw to connect to only mysql then I need a separate connection to the database one with no pw :S If this is getting tiresome i'll wait until Tuesday and bugg the proff – Vereonix Oct 12 '13 at 21:16

0 Answers0