<?
$dbh = new PDO("mysql:host=localhost;dbname=mmaaaco_ksecor", "mmaaaco_ksecor", "hamilton");

//appropriate way to backup table on same server with timestamp.

$query = "CREATE TABLE IF NOT EXISTS `tmp` (
  `id` int(5) NOT NULL auto_increment,
  `fname` varchar(255) NOT NULL,
  `lname` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `uname` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `active` int(5) NOT NULL default '0',
  `signupdate` datetime NOT NULL,
  `lastlogin` datetime NOT NULL,
  `lastaction` datetime NOT NULL,
  `numtries` int(5) NOT NULL,
  `currpage` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ;
";
 
$sql =  $dbh->prepare($query);
 $sql->execute(); 
 /*"If you specify the IGNORE keyword in an INSERT statement, errors that
occur while executing the statement are treated as warnings instead.
For example, without IGNORE, a row that duplicates an existing UNIQUE
index or PRIMARY KEY value in the table causes a duplicate-key error
and the statement is aborted. With IGNORE, the error is ignored and the
row is not inserted."
*/
 $insert = "INSERT IGNORE INTO tmp SELECT * FROM sp13members";
 $ins = $dbh->prepare($insert);
 $ins->execute();
  
  $date = date('m_d_Y');
  
  $newname = $date.'_sp13members'; 

 $alter =  "ALTER TABLE tmp RENAME TO $newname";
 $alt = $dbh->prepare($alter);
 $alt->execute();
 echo 'backed up to '.$newname;
?>