无法在Wordpress中创建表格

时间:2018-12-24 07:43:54

标签: php wordpress

我无法在wordpress中创建表格,我不明白为什么?

private function create($prefix)
{
    $sql = "CREATE TABLE " . $prefix . "submit (
            submit_id bigint PRIMARY KEY AUTO_INCREMENT,
            post_id bigint,
            user_id bigint,
            author text,
            user_email text,
            source text,
            pass text,
            language text,
            time datetime,
            CONSTRAINT post_id FOREIGN KEY (post_id) REFERENCES wp_posts(ID),
            CONSTRAINT user_id FOREIGN KEY (user_id) REFERENCES wp_users(ID)
        )";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    var_dump(dbDelta($sql));
}

var_dump()显示:

  

array(1){[“” wp_submit“] =>字符串(23)”创建的表wp_submit“}

1 个答案:

答案 0 :(得分:0)

add_action("after_switch_theme", "my_custom_table_setup");

 function my_custom_table_setup() 

 {



global $wpdb;
    $create_table_query = "


CREATE TABLE {$wpdb->prefix}products_by_sku (
          id int(11) NOT NULL  auto_increment,
          product_id int(11) NOT NULL,
          lot_id varchar(25) NOT NULL,
          title varchar(255) NOT NULL,
          LP varchar(25) NOT NULL,
          catgeory varchar(255) NOT NULL,
          product_name varchar(255) NOT NULL,
          UPC varchar(255) DEFAULT NULL,
          ASIN varchar(255) DEFAULT NULL,
          original_retail_price float DEFAULT NULL,
          quantity int(11) DEFAULT NULL,
          total_original_retail float NOT NULL DEFAULT 0,
          stock_image text,
          PRIMARY KEY  (id)
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;   


    ";
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        dbDelta( $create_table_query );



 }

尝试此代码。

谢谢。