PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 11, 2017 10:01 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Oct 13, 2017 10:49 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
We might be required to create a website whereby administrators can import a CSV into it.

I've done queries where you export a CSV, but not import.

Is it easy to do?
I know I would need to tie up the column headers in the CSV to the field headers in the database, but no idea how.

Any help would be appreciated.

Thanks.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 10:55 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
Take a look at LOAD DATA INFILE.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 11:00 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
Bloody hell that is a lot to read.
Surely it's more straight forward than that???

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 3:42 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
It's complicated because reading CSVs, processing data, and adding to a table is a complicated process.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 3:46 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
Often a practical solution, with some comments is better than [lots] [and] [lots] of tags on a screen that to some, is unreadable.

I had a Google for it and found a few results, with comments. Because the page you sent, sadly was just 'greek' to me. Sorry.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 3:56 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 491
Location: Victoria, BC
I use something like:

Syntax: [ Download ] [ Hide ]
LOAD DATA LOCAL
        INFILE 'your file goes here.CSV'
INTO TABLE
        `your database goes here`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 0 LINES;
 


everybody's favorite, SQL to the rescue

the code expects the CSV to be uploaded to the same box (VM) as the database server

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 4:16 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
I Was reading about it and saw the script to look at the uploaded file.
Then the query. It seemed to ut each row into some sort of array,[0], [1]... and that went into insert script, lined up with the field names in the DB.

Into a Row.

A practical actual idea of the script is easier to learn from. That's what I mean.
Then comments to explain each part.
Rather than ... ENGINE + BRAKES + CALIPERS = Move then Stop.
An actual explanation of what the engine is doing, what the brakes are doing and so on.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Sat Oct 14, 2017 8:43 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6402
Location: Montreal, Canada
If you don't want to go with the method suggested above, you can do it all in PHP if you think that would be easier to understand. You reference a script in your last post, but didn't post it. Do you have anything written yet? What are you stuck on?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group