Chloe MieMie Wang
Chloe MieMie Wang

Reputation: 71

how to load text file data into mysql using php?

This is the example of my text file:

Name: Chloe
Class: 1A
School: EEE

This is my database:

Name      Class     School

How do I input the text file data into my database using php? Thank you.

Upvotes: 0

Views: 932

Answers (2)

Kevin Burton
Kevin Burton

Reputation: 11936

This will help read a line in the file into an array:

see: http://www.homeandlearn.co.uk/php/php10p7.html

now once you have the 3 lines, you just need to get the data into your database....

here's some info on the command you will probably need to use to insert/update the data http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

here's some useful info on reading files : http://www.w3schools.com/PHP/php_file.asp

Upvotes: 1

Andrej
Andrej

Reputation: 7504

See more info http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Load DATA INFILE 'file_name' into table table_name FIELDS TERMINATED BY '\t'

PHP code

$pdo = new PDO(connection settings);
$pdo->exec($mysql_query);

Upvotes: 0

Related Questions