SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)

    Re-name Table to a Variable

    Hi.

    I'm trying to set up an auto back-up thing on a database table.

    I'd like the back-up name to be the table's name, then a space, and the date and timestamp.

    The following syntax isn't working though. Can anyone advise how it should be done instead?


    Code PHP:
    /* Re-name the Current Table as a Back Up */
     
    	// Connect to Database
    		@ include($_SERVER['DOCUMENT_ROOT'] . '/protected/table-info.php');
    		@ mysql_connect($db_Host,$db_Username,$db_Password);
    		@ mysql_select_db($db_Database) or die("Server too busy. Please try again later.");
     
    	// Re-name Table
    		$backup_name = 'yellow_categories ' . date('Y-m-d') . '_' . time();
    		$query = "RENAME TABLE yellow_categories TO $backup_name";
    		mysql_query($query);
     
    	// Dis-connect from Database
    		@ mysql_close();
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  2. #2
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    I also tried it without the space, by the way, and that version didn't do anything either.

    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,019
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Try:

    PHP Code:
    /* Re-name the Current Table as a Back Up */ 
        // Connect to Database        @ include($_SERVER['DOCUMENT_ROOT'] . '/protected/table-info.php');        @ mysql_connect($db_Host,$db_Username,$db_Password);        @ mysql_select_db($db_Database) or die("Server too busy. Please try again later."); 
        // Re-name Table        $backup_name = 'yellow_categories ' . date('Y-m-d') . '_' . time();        $query = "RENAME TABLE yellow_categories TO '$backup_name'";        mysql_query($query); 
        // Dis-connect from Database        @ mysql_close(); 
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but it didn't work.

    I think it's something to do with the dashes in the date(); part. When I change $backup_name to just 'yellow_categories' and a timestamp, it works just fine.

    That'll do though.

    Thanks a lot.

    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse


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
  •