Insert data from .sql file in wordpress plugin

I'm creating a wordpress plugin that need to create a table and insert location data to that. There are more than 50000 locations in that INSERT query, so that in separate .sql file.

I need to run that when I active the plugin. I'm creating table like below

function locations_install()
{
    global $wpdb;
    global $locations_db_version;

    $table_name = $wpdb-prefix . 'setfordslocations';

    $charset_collate = $wpdb-get_charset_collate();

    $sql = "CREATE TABLE IF NOT EXISTS $table_name (
            id int(11) NOT NULL AUTO_INCREMENT,
            town varchar(2000) CHARACTER SET utf8 DEFAULT NULL,
            county varchar(225) NOT NULL,
            country varchar(225) NOT NULL,
            latitude decimal(10,5) DEFAULT NULL,
            longitude decimal(10,5) DEFAULT NULL,
            postcode varchar(10) NOT NULL,
            type varchar(255) NOT NULL,
            PRIMARY KEY  (id)
        ) $charset_collate;";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);

    add_option('locations_db_version', $locations_db_version);
}

How should I run the .sql file and insert data?

Topic mysql plugin-development plugins Wordpress

Category Web


in your plugin activator function write your code without function or if you want to do with function call this function in you activate function.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.