query( "SHOW TABLES LIKE '".$dbw->escapeLike($old)."%'" ); foreach( $res as $row ) { // XXX: odd syntax. MySQL outputs an oddly cased "Tables of X" // sort of message. Best not to try $row->x stuff... $fields = get_object_vars( $row ); // Silly for loop over one field... foreach( $fields as $resName => $table ) { // $old should be regexp safe ([a-zA-Z_]) $newTable = preg_replace( '/^'.$old.'/',$new,$table); print "Renaming table $table to $newTable\n"; $dbw->query( "RENAME TABLE $table TO $newTable" ); } $count++; } print "Done! [$count tables]\n";