kat35601 Posted October 22, 2012 Share Posted October 22, 2012 I have a file with a little over one million rows and would like to put it in a mysql database. But I am not sure of the best and easyist way. MY Table: create table dbo.PUBACC_EN ( record_type char(2) not null, unique_system_identifier numeric(9,0) not null, uls_file_number char(14) null, ebf_number varchar(30) null, call_sign char(10) null, entity_type char(2) null, licensee_id char(9) null, entity_name varchar(200) null, first_name varchar(20) null, mi char(1) null, last_name varchar(20) null, suffix char(3) null, phone char(10) null, fax char(10) null, email varchar(50) null, street_address varchar(60) null, city varchar(20) null, state char(2) null, zip_code char(9) null, po_box varchar(20) null, attention_line varchar(35) null, sgin char(3) null, frn char(10) null, applicant_type_code char(1) null, applicant_type_other char(40) null, status_code char(1) null, status_date datetime null I attached a file with sample data. data.txt Quote Link to comment https://forums.phpfreaks.com/topic/269777-use-php-to-parse-a-file-to-mysql-newbieway-newbie/ Share on other sites More sharing options...
shaddowman Posted October 22, 2012 Share Posted October 22, 2012 I think a good way to put it in mySQL is by exploding each line and getting it's element inserted in the database one by one. So you're going to read each line and explode it, then insert it to the database then move to the next line. Another way is to parse it and put all in object array and then insert it in the database. Quote Link to comment https://forums.phpfreaks.com/topic/269777-use-php-to-parse-a-file-to-mysql-newbieway-newbie/#findComment-1386987 Share on other sites More sharing options...
Christian F. Posted October 22, 2012 Share Posted October 22, 2012 By the looks of it, you should read up on database normalization as well. So that you can make your database design into a logical model, and thus leverage the true capabilities of the DB engine. Not to mention all of the headaches it'll save you in the long run. I recommend watching this series of movies, as they'll give you a fairly good introduction into the subject. Quote Link to comment https://forums.phpfreaks.com/topic/269777-use-php-to-parse-a-file-to-mysql-newbieway-newbie/#findComment-1387040 Share on other sites More sharing options...
mikosiko Posted October 22, 2012 Share Posted October 22, 2012 (edited) ^+1 one easy way : LOAD DATA INFILE Edited October 22, 2012 by mikosiko Quote Link to comment https://forums.phpfreaks.com/topic/269777-use-php-to-parse-a-file-to-mysql-newbieway-newbie/#findComment-1387052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.