Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a better solution to create a database table for a WordPress Plugin? How can I simplify this query? What code improvements could be made in this code? Any ideas would be great.

register_activation_hook(__FILE__, 'my_plugin_create_db');

function my_plugin_create_db() {
    global $wpdb;
    $name = 'my_table';
    $charset_collate = $wpdb->get_charset_collate();
    $table_name = $wpdb->prefix . $name;
    $sql = "CREATE TABLE $table_name("
            . "id int(9) NOT NULL AUTO_INCREMENT,"
            . "time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,"
            . "views int(9) NOT NULL,"
            . "clicks int(9) NOT NULL,"
            . "UNIQUE KEY id (id)"
            . ")$charset_collate;";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.