get_results("SHOW TABLES"); foreach ($mytables as $mytable) { foreach ($mytable as $t) { $old_collation = $wpdb->get_var("SELECT TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_NAME = '$t'"); WP_CLI::line("Table {$t} current collation: {$old_collation}"); $converted = maybe_convert_table_to_utf8mb4($t); if ($converted) { $new_collation = $wpdb->get_var("SELECT TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_NAME = '$t'"); WP_CLI::line("Table {$t} converted. New collation: {$new_collation}"); } } } } } // Ensure WP_CLI class exists before adding the command. if (class_exists('WP_CLI')) { // Register our new CLI command. WP_CLI::add_command('upgrade_utf8mb4', 'utf8mb4_Database_Upgrade'); } }