useDB() public method

public useDB ( )
示例#1
0
function archive_lmt_db($uname, $passw, $yrfrom, $yrto)
{
    $yrfrom = intval($yrfrom);
    $yrto = intval($yrto);
    //Reconnect with the new username/password with more privileges
    $adminDB = new MeekroDB(NULL, $uname, $passw);
    //create new db
    //probably triggers error if already exists
    $adminDB->query("CREATE DATABASE  `lmt-{$yrfrom}` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci");
    $adminDB->useDB('lmt-' . $yrfrom);
    //copy db info to new db
    //This can be done dynamically using SHOW TABLES but this is easier.
    $tables = array('guts', 'individuals', 'map', 'pages', 'schools', 'teams');
    foreach ($tables as $table) {
        $adminDB->query("CREATE TABLE  `lmt-{$yrfrom}`.`{$table}` LIKE `lmt`.`{$table}`");
        $adminDB->query("INSERT `lmt-{$yrfrom}`.`{$table}` SELECT * FROM `lmt`.`{$table}`");
    }
    //truncate necessary fields in LMT db, since it's already archived.
    $tables_truncate = array('guts', 'individuals', 'schools', 'teams');
    foreach ($tables_truncate as $table) {
        $adminDB->query("TRUNCATE TABLE `lmt`.`{$table}`");
    }
}