无法使用我的插件创建表格

时间:2012-12-30 作者:fpilee

代码如下:

<?php

/*
  Plugin Name: MyPluggin
  Plugin URI: http://localhost/
  Description: 
  Version: 0.0.2
  Author: localhost
  Author URI: http://localhost/
  License: GPL2
 */


function crear_tablas() {

    global $wpdb;


    require_once(ABSPATH . \'wp-admin/includes/upgrade.php\');


    $table_name_1 = $wpdb->prefix . "usuarios";
    $consulta_1 = "create table $table_name_1(
                count bigint unsigned not null  primary key auto_increment,
                ID bigint not null references wp_users(ID),
                puntosDisponibles bigint unsigned default 1000
            );";

    dbDelta($consulta_1);


    $table_name_2 = $wpdb->prefix . "deportes";
    $consulta_2 = "create table $table_name_2(
                ID int unsigned not null  primary key auto_increment,
                nombre tinytext
            );";

    dbDelta($consulta_2);

    $table_name_3 = $wpdb->prefix . "ligas";
    $consulta_3 = "create table $table_name_3(
    ID int unsigned not null  primary key auto_increment,
    nombre tinytext
);";

        dbDelta($consulta_3);


    $table_name_4 = $wpdb->prefix . "equipos";
    $consulta_4 = "create table $table_name_4(
    ID int unsigned not null  primary key auto_increment,
    nombre tinytext,
    apodo  tinytext,
    deporte int unsigned not null references deportes(id),
    liga    int unsigned not null references ligas(id)

);";

        dbDelta($consulta_4);

        $table_name_5 = $wpdb->prefix . "eventos";
    $consulta_5 = "create table $table_name_5(
    count bigint unsigned not null  primary key auto_increment,
    ID  bigint unsigned not null references wp_posts(ID),
    localID int unsigned not null references equipos(ID),    
    visitanteID int unsigned not null references equipos(ID),
    goleslocal  int unsigned,
    golesVisitante  int unsigned,
    fecha DATE not null,
    hora  TIME not null,     
    status  int unsigned default 0

);";

        dbDelta($consulta_5);

    $table_name_6 = $wpdb->prefix . "apuestas";
    $consulta_6 = "create table $table_name_6(
    count bigint unsigned not null  primary key auto_increment,
    eventoID bigint unsigned not null references   wp_posts(ID),
    puntosJugados   bigint unsigned not null,
    userID  bigint unsigned not null references wp_users(ID), 
    fecha DATE not null,
    hora  TIME not null,     
    resultado int unsigned not null,
    porcentaje float(4,2),
    estado int unsigned not null default 0
);";

        dbDelta($consulta_6);

}






function instalar_sistema_apuestas () {
    crear_tablas();
    //crearCategorias();
    //crearPaginaPerfil();

 }

register_activation_hook(__FILE__,\'instalar_sistema_apuestas\');







?>
未创建任何表:

mysql> show tables;
+------------------------+
| Tables_in_wordpress |
+------------------------+
| wp_commentmeta         |
| wp_comments            |
| wp_links               |
| wp_options             |
| wp_postmeta            |
| wp_posts               |
| wp_term_relationships  |
| wp_term_taxonomy       |
| wp_terms               |
| wp_usermeta            |
| wp_users               |
+------------------------+
11 rows in set (0.00 sec)

1 个回复
SO网友:stealthyninja

您的所有create table 命令必须为大写才能使用dbDelta(). It\'s "picky".

结束

相关推荐

这个错误是什么意思?WordPress数据库错误:[MySQL服务器已消失]

WordPress数据库错误:[MySQL服务器已离开]我没有做任何更改,主机说MySQL没有问题。谁能解释一下这个错误是什么意思吗?以及如何排除故障?这是一个共享的托管环境,最近没有对站点进行任何更改。同样,其他wordpress站点也遇到了这个共享服务器的问题。