SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Restore Database From Link in Page

    I want to have a demo on my site to show how AJAX updating works and want people to be able to edit the fields. But, I don't want people putting in offensive stuff.

    I think the best way would be to have a "Restore Database" link and so the next user can hit the link and revert back to the test data that I had originally inputted.

    I can't find anywhere that tells me how to do this, but I know it has been done.

    Anyone got any ideas?

    Pages are in PHP & database is MySQL.

    Ta, Ian

  2. #2
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not to worry

    I actually managed to find something...

    If anyone else wants it, it's
    PHP Code:
    <?php

    require ('includes/dbconnect.php');

    $filename 'data/mysqldump.sql';

    $templine '';

    $lines file($filename);

    foreach (
    $lines as $line_num => $line) {
        if (
    substr($line02) != '--' && $line != '') {
            
    $templine .= $line;
            if (
    substr(trim($line), -11) == ';') {
                
    mysql_query($templine) or print('Error performing query \'<b>' $templine '</b>\': ' mysql_error() . '<br /><br />');
                
    $templine '';
            }
        }
    }

    header("Location: /");
    ?>
    Just remember to have a "drop table" instruction in the MySQl dump file.

    I got it from http://www.daniel15.com/blog/2006/12...ump-using-php/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •