Esempio n. 1
0
function compare()
{
    init();
    //如果目标数据库不存在,先创建一个
    $sql = 'create database if not exists ' . TARGET_DB . ' default charset utf8 collate utf8_general_ci';
    mysql_query($sql, TARGET_LINK);
    //获取数据源的数据结构
    $source_database_struct = get_database_struct(SOURCE_LINK, SOURCE_DB);
    //获取目标的数据结构
    $target_database_struct = get_database_struct(TARGET_LINK, TARGET_DB);
    //以数据源为准,比较差异
    foreach ($source_database_struct as $table_name => $create_table) {
        if (!$target_database_struct[$table_name]) {
            execute($create_table, TARGET_LINK);
        } else {
            //比较字段
            compare_column(SOURCE_LINK, TARGET_LINK, SOURCE_DB, TARGET_DB, $table_name);
            //比较索引
            compare_keys(SOURCE_LINK, TARGET_LINK, SOURCE_DB, TARGET_DB, $table_name);
            //比较分区
            compare_partition(SOURCE_LINK, TARGET_LINK, SOURCE_DB, TARGET_DB, $table_name);
        }
    }
    //删除多余的表
    foreach ($target_database_struct as $table_name => $create_table) {
        if (!$source_database_struct[$table_name]) {
            $sql = 'drop table ' . $table_name;
            execute($sql, TARGET_LINK);
        }
    }
    close();
}
 public function import_posts()
 {
     $response = wp_remote_get('http://deep-thoughts.dev/wp-json/wp/v2/posts/');
     if (is_wp_error($response)) {
         return;
     }
     $post_data = json_decode(wp_remote_retrieve_body($response));
     if (compare_keys()) {
         insert_or_update($post_data);
     }
     wp_die();
 }