Jump to content


CSV files

  • Please log in to reply
3 replies to this topic

#1 Jimbo_17

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 June 2006 - 02:26 AM

Is there any way to load a CSV file into anything like the mysql functions in PHP. For example, PERL can open a CSV file and run queries on it as though it were an SQL database.

#2 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 June 2006 - 05:03 AM

I've done this before... fopen() fgets(), then explode() by comma.

No sorting, no joining, no relations, no indexing, and rudimentary searching. Depending on the size of the file, it might even be snail slow.

Better idea: Write a converter to put your CSV into a mysql database. I have several of these running through cron. They download the CSV file via FTP, parse it, and dump it into a mysql database -- every day. MySQL loves doing advanced searches and sorts lightning fast.

#3 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 June 2006 - 05:36 AM

Instead of
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]fopen() fgets(), then explode() by comma.[/quote]
you really should look at the [a href=\"http://www.php.net/fgetcsv\" target=\"_blank\"]fgetcsv()[/a] function, since it knows how to handle commas inside a quoted string.


#4 litebearer

  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 23 June 2006 - 11:54 AM

Might look at these...

[a href=\"http://www.c-worker.ch/txtdbapi/index_eng.php\" target=\"_blank\"]http://www.c-worker.ch/txtdbapi/index_eng.php[/a]

[a href=\"http://ffdb-php.cvs.sourceforge.net/ffdb-php/README?revision=1.6&view=markup\" target=\"_blank\"]http://ffdb-php.cvs.sourceforge.net/ffdb-p...1.6&view=markup[/a]


all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users