这是我创建表的php页面,现在我想更新表。无法做到。
<?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:
保存了上面的页面后,我禁用了插件并激活了插件以查看更改,但没有任何更改低于警告
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.