1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Reading a MySQL Dump File

Discussion in 'PHP' started by kc3, Jan 28, 2007.

  1. #1
    When you export a mysql file with PhpMyAdmin how do you make a php script read the file and excecute it? This means with all the formatting added by PhpMyAdmin like new lines between different fields of a database.
     
    kc3, Jan 28, 2007 IP
  2. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It depends on how you exported it and what you need to do: if it's exported as MySQL you can just feed it to another phpMyAdmin, give it directly to the mysql client or import it in a PHP script and execute a query with it.

    If it's a comma delimited file you can read it with 'file()' or 'file_get_contents()' and then parse it
     
    picouli, Jan 28, 2007 IP
  3. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As mentioned above you'll need to explain more on what it looks like.. but it would be much more efficient to just pop it in another PHPMyAdmin and import it.. or if you have shell access type the following:

    
    mysql -uuser -ppassword database < mysqldump.sql
    
    Code (markup):
     
    CodyRo, Jan 29, 2007 IP
  4. lmoss

    lmoss Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The default dump format is simply to output a series of SQL commands that, when executed by MySQL, recreate the database from scratch.
     
    lmoss, Jan 29, 2007 IP
  5. kc3

    kc3 Peon

    Messages:
    857
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The dump file looks like this
    That's just an example but the way I did it interpreted each line as it's own command so it tried to excecute the blank lines, username text, email text ) and the other lines as if they were they're own seperate commands. Btw I'm making a software that needs to read it that's why I don't just use phpmyadmin to re-upload the database.
     
    kc3, Jan 30, 2007 IP
  6. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #6
    maratz.com/blog/archives/2005/06/05/send-database-backup-to-your-mailbox-with-backup2mail/

    Use your imagination and add the http & www stuff above as I cannot post live links yet.

    Here is a handy program (not mine) that will allow you to hit a page and get the sql dump sent to you. I have been using this for about a year, it's being pushed by windows scheduler since I do not have access to cron on my shared server. I just have my homepages set to the backup2db folder of each of my sites in an infrequently used browser (ie7) that launches (by scheduler) once daily. The end result is that I have gmail backups incase of emergency.

    These dumps are properly formatted and can just be entered in the SQL section of phpmyadmin. You can restore to a previous state in a few mouseclicks and a wee bit of typing.
     
    ErectADirectory, Jan 31, 2007 IP
  7. kc3

    kc3 Peon

    Messages:
    857
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That's not what I'm trying to do, I'm trying to make a php script that will automaticaly read the dump file and load it into the mysql database.
     
    kc3, Jan 31, 2007 IP
  8. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Gotcha, restore database . . . not backup

    How about this post about

    daniel15.com/blog/2006/12/09/restore-mysql-dump-using-php/

    restoring MySql dump

    I used it along with my backup created with the other program I posted and it worked out fine.

    hope this helps
     
    ErectADirectory, Feb 1, 2007 IP
  9. kc3

    kc3 Peon

    Messages:
    857
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks :) That's exactly what I needed, thanks for your help
     
    kc3, Feb 4, 2007 IP