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?