1

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?

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.