parse CSV headers & dynamically generate SQL table?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Epstein

    #1

    parse CSV headers & dynamically generate SQL table?

    I have a collection of CSV datasets which will all contain different
    numbers of columns and different column headers. There will always be
    a fixed number of such files and they have some common
    characteristics , especially those with column names in common (e.g.,
    at some point I will be performing some database joins based upon
    similar column names).

    Initially I would like to parse each CSV file and automatically create
    a mySQL table containing fields corresponding to the CSV file headers.

    In some subsequent web page(s) I will be performing some boolean
    queries against this mySQL database, and will need to query the field
    names on the fly so that I can create suitable drop-down lists for the
    user to formulate her query.

    I'm really a Perl programmer, but have a feeling that this will be
    much easier in PHP.

    Thanks in advance for any pointers.

    Jonathan
  • R. Rajesh Jeba Anbiah

    #2
    Re: parse CSV headers & dynamically generate SQL table?

    jaepstein_63@ya hoo.com (Jonathan Epstein) wrote in message news:<27e4d2e8. 0404150701.5c3e 61be@posting.go ogle.com>...[color=blue]
    > I have a collection of CSV datasets which will all contain different
    > numbers of columns and different column headers.[/color]

    <snip>

    Is it what you're looking for <http://in.php.net/fgetcsv> ?

    --
    http://www.sendmetoindia.com - Send Me to India!
    Email: rrjanbiah-at-Y!com

    Comment

    • Jonathan Epstein

      #3
      Re: parse CSV headers &amp; dynamically generate SQL table?

      Thanks, this helps with the parsing. The next step (and the more difficult
      one) is to create the database on the fly.

      But the web site you showed me also shows how to create databases and tables
      using mysql_query() so I think that I'm more-or-less in business.

      Refs for other PHP newbies:


      (note deprecation of mysql_create_db () but instructions for use of CREATE
      DATABASE are also provided)

      Jonathan

      "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
      news:abc4d8b8.0 404151956.49e9f 508@posting.goo gle.com...[color=blue]
      > jaepstein_63@ya hoo.com (Jonathan Epstein) wrote in message[/color]
      news:<27e4d2e8. 0404150701.5c3e 61be@posting.go ogle.com>...[color=blue][color=green]
      > > I have a collection of CSV datasets which will all contain different
      > > numbers of columns and different column headers.[/color]
      >
      > <snip>
      >
      > Is it what you're looking for <http://in.php.net/fgetcsv> ?
      >
      > --
      > http://www.sendmetoindia.com - Send Me to India!
      > Email: rrjanbiah-at-Y!com[/color]


      Comment

      Working...