title: Wordpress how to create table on plugin activation
body: <p>Here is my code, I write create query into function and call that in <code>register_activation_hook()</code> function, but it's not working.</p>
  
  <pre><code>function test_contact_form() {      
          global $wpdb; 
          $connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
          mysql_select_db(DB_NAME);        
          if (!$connection){ die('Error: ' . mysql_error());}
  
      require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
  
      $db_table_name = $wpdb-&gt;prefix . 'contactus_detail';  // table name
      if( $wpdb-&gt;get_var( "SHOW TABLES LIKE '$db_table_name'" ) != $db_table_name ) {
          if ( ! empty( $wpdb-&gt;charset ) )
              $charset_collate = "DEFAULT CHARACTER SET $wpdb-&gt;charset";
          if ( ! empty( $wpdb-&gt;collate ) )
              $charset_collate .= " COLLATE $wpdb-&gt;collate"; 
          $sql = "CREATE TABLE " . $db_table_name . " (
              id int(11) NOT NULL auto_increment,
                          ip varchar(15) NOT NULL,
                          name varchar(60) NOT NULL,
                          emailid varchar(200) NOT NULL,
                          mobileno varchar(10) NOT NULL,
                          message varchar(1000) NOT NULL,
                          PRIMARY KEY (id) 
          ) $charset_collate;";
  
  
  dbDelta( $sql ); // create query 
          }  
      }
      register_activation_hook(__FILE__, 'test_contact_form');
  </code></pre>