This is the php page through which i created the table , now i want to update the table. Not not able to do.
<?php
/**
* @package wplab-campaign
* @version 1.0
*/
/*
Plugin Name: Wplab Campaign
Description: Sinple Pluign to host capaign
Author: Saurabh Ranjan
Version: 1.0
*/
function my_plugin_create_db() {
global $wpdb;
$version = get_option( 'my_plugin_version', '1.0' );
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'my_analysis';
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
views smallint(5) NOT NULL,
clicks smallint(5) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
if ( version_compare( $version, '2.0' ) < 0 ) {
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
views smallint(5) NOT NULL,
clicks smallint(5) NOT NULL,
blog_id smallint(5) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta( $sql );
update_option( 'my_plugin_version', '2.0' );
}
}
function my_plugin_insert_db() {
global $wpdb;
$table_name = $wpdb->prefix . 'my_analysis';
$views = "1";
$clicks = "1";
$blog_id = "123s";
$rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'views' => $views, 'clicks' => $clicks, 'blog_id' =>$blog_id ) );
}
function my_activation_func() {
file_put_contents( __DIR__ . '/wplab-campaign-log.txt', ob_get_contents() );
}
register_activation_hook( __FILE__, 'my_activation_func' );
register_activation_hook( __FILE__, 'my_plugin_create_db' );
register_activation_hook( __FILE__, 'my_plugin_insert_db' );
Note:
After saving the above page , I disabled the plugin and activated the plugin to see the changes , but nothing change even got below warning
The plugin generated 585 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.