How to change theme programmatically from a external application?

Take a look at the options table:

$opt_table = "{$GLOBALS['wpdb']->prefix}_options";
$parent_theme = $opt_table + template;
$child_theme = $opt_table + stylesheet;