Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here is the code:

<?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');







?>


No tables were created:

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)
share|improve this question
    
Have you enabled debugging? If so, do you have any debugging information –  s_ha_dum Dec 30 '12 at 18:33
add comment

1 Answer

All of your create table commands must be in uppercase in order for it to work with dbDelta(). It's "picky".

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.