Support » Plugins and Hacks » No database tables created after instalation

  • Hello am trying to create a WP- Plugin that has up to 4 different database tables, the problem i have is that it says that plugin is activated but when i search the phpmyadmin i dont see the tables created at my database.
    Here is the code i am using

    <?php
    /*
    	Plugin Name: Reservations
    	Version: 0.1
    	Plugin URI: www.google.com
    	Description: Lets you choose reservations dates when available,set which days are unavalaible,minimun days to book, you can set different prices related to object of booking and/or date booked.
    	Set prices by range dates (seasons) giving them a diferent background color + leyenda
    	Pre-pay selected days (completely/or by fianza)
    	Author: Javier Moñiz
    	Author URI: http://javiermoniz.wordpress.org
    
        Copyright 2009  Javier Moñiz Juliá  (email : see web contact)
        Licence:
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    
    	FUNCION DE INSTALACIÓN SOLO SE ACTIVA SI EL PLUGIN NO ESTA ACTIVO
    */
       register_activation_hook('wp-content/plugins/reservations/reservations.php', 'reservations_install');
    
    	//register_activation_hook(__FILE__,'reservations_install');
    	register_deactivation_hook('wp-content/plugins/reservations/reservations.php','reservations_deactivate');
    	$reservations_db_version = "1.0";
    
    function reservations_install (){
       global $wpdb;
       global $reservations_db_version;
    
       // Creo la tabla temporada si no existe ya
       // esta tabla contiene las fechas de inicio y fin de las temporadas
       $table_name = $wpdb->prefix . "temporada";
       var_dump($table_name);
       if($wpdb->get_var("show tables like '$table_name'") != $table_name)
    	   {
    			$sql = "CREATE TABLE $table_name (
    			id_temporada mediumint(9) NOT NULL AUTO_INCREMENT,
    			nombre_temporada varchar(64) NOT NULL,
    			fecha_ini timestamp NOT NULL,
    			fecha_fin timestamp NOT NULL,
    			uso_tarifa mediumint(9),
    			UNIQUE KEY id (id_temporada)
    			);";
    			dbDelta($sql);
    	   }
    
    //   // Creo la tabla tarifas si no existe ya
    	$table_name = $wpdb->prefix . "tarifas";
    	if($wpdb->get_var("show tables like '$table_name'") != $table_name)
    	{
    			$sql = "CREATE TABLE $table_name (
    			id_tarifa mediumint(9) NOT NULL AUTO_INCREMENT,
    			nombre_tarifa varchar(64) NOT NULL,
    			precio_tarifa int,
    			fecha_ini timestamp NOT NULL,
    			fecha_fin timestamp NOT NULL,
    			UNIQUE KEY id (id_tarifa)
    			);";
    			dbDelta($sql);
        }
    //
    //	// Creo la tabla reservas si no existe ya
        $table_name = $wpdb->prefix . "reservas";
    	if($wpdb->get_var("show tables like '$table_name'") != $table_name)
    	{
    			$sql = "CREATE TABLE $table_name (
    			id_reserva mediumint(9) NOT NULL AUTO_INCREMENT,
    			nombre_cliente varchar(64) NOT NULL,
    			email_cliente varchar(64) NOT NULL,
    			pagado_parcial int,
    			pagado_total int,
    			fecha_ini_reserva timestamp NOT NULL,
    			fecha_fin_reserva timestamp NOT NULL,
    			UNIQUE KEY id (id_reserva)
    			);";
    			dbDelta($sql);
    	}
    //
    //	// Creo la tabla vinculos si no existe ya
    	$table_name = $wpdb->prefix . "vinculos";
        if($wpdb->get_var("show tables like '$table_name'") != $table_name)
        {
    		$sql = " CREATE TABLE $table_name (
    		id_vinculo mediumint(9) NOT NULL AUTO_INCREMENT,
    		id_reserva mediumint(9) NOT NULL,
    		id_temporada mediumint(9) NOT NULL,
    		id_tarifa mediumint(9) NOT NULL,
    		UNIQUE KEY id (id_vinculo)
    		);";
    		dbDelta($sql);
        }
    }	  
    
    //	// registrar la función que se ejecuta al desactivar el plugin
    
    //
    //// función que se ejecuta al desactivar el plugin
    function reservations_deactivate()
    {
    //    // borrar las tablas del plugin
        global $wpdb;
        $table_name = $wpdb->prefix."reservations,";
        $table_name.= $wpdb->prefix . "temporada,";
        $table_name.= $wpdb->prefix . "tarifas,";
        $table_name.= $wpdb->prefix . "reservas,";
        $table_name.= $wpdb->prefix . "vinculos";
        $sql = "DROP TABLE $table_name";
        $wpdb->query($sql);
    //
    //    // borrar la option del plugin
        delete_option(’reservations_saludo_type’);
    }
    ?>

Viewing 1 replies (of 1 total)
  • dbDelta is extremely, frustratingly, picky. Are you sure you’ve got everything right, especially this:

    * You have to put each field on its own line in your SQL statement.
    * You have to have two spaces between the words PRIMARY KEY and the definition of your primary key.
    * You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY.

Viewing 1 replies (of 1 total)
  • The topic ‘No database tables created after instalation’ is closed to new replies.