I am new to wordpress plugin development. I want to create a new table when someone installs the plugin and populate the daata from csv file into the table.
Here is my code to create table:
$sql = "CREATE TABLE $table_name (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`location` varchar(150) NOT NULL,
`slug` varchar(150) NOT NULL,
`population` int(10) unsigned NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
$wpdb->query($sql);
After running this table is created.
Issue is that I am finding it difficult to populate data.csv into the table.
In windows xampp it is working
$current_plugin_dir = dirname(__FILE__);
$current_plugin_dir = str_replace("\\","\\\\",$current_plugin_dir);
$current_plugin_dir = $current_plugin_dir . '\\\\data.csv';
$sql = "LOAD DATA LOCAL INFILE '$current_plugin_dir' INTO TABLE $table_name";
$wpdb->query($sql);
While live server it is not working... But following code works...
$current_plugin_dir = $current_plugin_dir.'/data.csv';
$sql = "LOAD DATA LOCAL INFILE '$current_plugin_dir' INTO TABLE $table_name";
$wpdb->query($sql);
But in my ubuntu operating system no one seems to work.. I debugged and it seems following query ran on ubuntu lamp environment
LOAD DATA LOCAL INFILE '/var/www/html/testwp/wp-content/plugins/plugin-name/data.csv' INTO TABLE test_population
and it triggered following error
1148 - The used command is not allowed with this MySQL version
Is there any single way of loading csv on all platforms? Any help?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire