how to restore .csv or .sql in database by php?

Discussion in 'PHP' started by kcm4web, Nov 11, 2010.

  1. #1
    hi Php gurus...

    i am a newbie so pls help me...
    my client wants he will manage to upload csv or .sql file by file field and the the data will populate in the database. i am using php and my sql .how can i do this ..pls help me
     
    kcm4web, Nov 11, 2010 IP
  2. tnd8

    tnd8 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try 2 following ways:

    1. Easy way: you can using phpmyadmin.net (mysql web client. you can find more at google with keyword "mysql manager" or "mysql web client"). With phpmyadmin, you can manage, backup, restore,... your mysql database. phpmyadmin also support cvs, sql,...

    2. Write a restore.php yourself ^__^
     
    tnd8, Nov 12, 2010 IP
  3. SedNaX

    SedNaX Active Member

    Messages:
    1,326
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    90
    #3
    If it's a .sql exported file it is already one big mysql query. Can't you just use file_get_contents to put the sql file in a string and then mysql_query() that string?

    csv is a different story, you'll need to read the file and use explodes to generate the right query. phpmyadmin is the easiest and fastest way.
     
    SedNaX, Nov 13, 2010 IP