DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • May 18, 2013, 10:08:50 AM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: Database Table not creating  (Read 302 times)
0 Members and 1 Guest are viewing this topic.
Aeo
Mod God
*****
Offline Offline

Posts: 1077


Doctor.. Who?


View Profile WWW
« on: July 21, 2012, 06:11:50 PM »

So, I have this module rpalignment, with the install function thus:

Code:
<?php
function rpalignment_install(){
include_once("modules/rpalignment/install.php");
return true;
}
?>


and the modules/rpalignment/install.php files goes as thus:

Code:
<?php
// database table creation
if (!db_table_exists(db_prefix("rpalignment"))){
$sql "CREATE TABLE `".db_prefix("rpalignment")."` (
  `name` varchar(255) NOT NULL default 'General',
  `id` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM COMMENT='This holds the rp alighment info for the Roleplay Alignment module.' AUTO_INCREMENT=1 ;"
;
db_query($sql);
}

// module hooks
module_addhook("biostat");
module_addhook("village");
module_addhook("superuser");
module_addhook("charstats");
module_addhook("header-village");
module_addhook("newday");
module_addhook("shades");
?>


However, when installing and activating the module, the database table rpalignment will not create, even though the whole module, database table and all, works PERFECTLY on my development server. >.< Anyone know of a fix or error I've done?
« Last Edit: July 21, 2012, 06:16:45 PM by Aeolus » Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Loscil Derails
Militia
**
Offline Offline

Posts: 51



View Profile
« Reply #1 on: July 21, 2012, 06:28:25 PM »

I'm not sure off of the top of my head what is the problem, but here are some things to check:

1) Did you make sure in the db that it didn't actually create? While it sounds like you have, I'm not sure if you were just going by if the module works or not.
2) Is your live DB a different build/version than your dev db?
3) Does it depend on any modules that you have active on your dev server but not on your live version? (If you wrote this module, did you remember to include dependencies?)
4) If uninstall and reinstall works perfectly on your dev server, it is unlikely you have a syntax error, unless there is anything that you changed the name of on your dev server and not on your live server (or vice versa: example, renaming a module, or anything)

That's all I can think of for now, if I see anything or think of anything else I'll let you know.
Logged

Your specimen is being processed...
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1000


Love bites, but so do I!


View Profile
« Reply #2 on: July 21, 2012, 06:50:06 PM »

Also, are the MySQL versions on the two servers the same, or are they different? I don't think MySQL v5.5 supports "Type" anymore. You may have to relace it with "engine" and see how that works.
Logged

My Mods
Like to read? "Like" my page. Smiley
For reasons I'd prefer not to explain, I will not be active until further notice. I will not make any posts and I will ignore all PMs.
Brendan
I am Brendan.
Mod God
*****
Offline Offline

Posts: 823


View Profile
« Reply #3 on: July 21, 2012, 06:50:27 PM »

Its the type.

EDIT..
Yeah what Kaizer said  Smiley
Logged
Aeo
Mod God
*****
Offline Offline

Posts: 1077


Doctor.. Who?


View Profile WWW
« Reply #4 on: July 21, 2012, 06:54:12 PM »

You may have to relace it with "engine" and see how that works.

Its the type.

My thanks! It works as it's meant to now. Grin


That's all I can think of for now, if I see anything or think of anything else I'll let you know.

Also, thanks valor for your help, too. Smiley
Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Loscil Derails
Militia
**
Offline Offline

Posts: 51



View Profile
« Reply #5 on: July 21, 2012, 06:59:05 PM »

Also, are the MySQL versions on the two servers the same, or are they different? I don't think MySQL v5.5 supports "Type" anymore. You may have to relace it with "engine" and see how that works.
This is what I meant in my number 2 option. ^^;
Logged

Your specimen is being processed...
Boris735
Mod God
*****
Offline Offline

Posts: 532


View Profile
« Reply #6 on: July 22, 2012, 07:20:12 AM »

You can avoid some of these issues -- or at least make them the fault of Green Dragon code Smiley -- by using synctable() (preferred) or table_create_from_descriptor() to create the table.

The benefits of this layer of abstraction are that those functions can, in principle, cope with different database requirements (so, for instance, that you don't have to think about whether ISAM or INNODB is the right one to use, or whatever later engines are invented) and also that synctable() will adjust the table if need be.  This latter is particularly handy when you decide you want a new column in the table, since you only need to change the definition and not write the checking code yourself.

The corresponding code for your example would be (note that no check is required for whether the table already exists):

Code:
$rpdesc = array(
  'id' => array('name' => 'id', 'type' => 'int(11)', 'extra' => 'auto_increment'),
  'name' => array('name' => 'name', 'type' => 'varchar(255)', 'default' => 'General'),
  'key-PRIMARY' => array('name' => 'PRIMARY', 'type' => 'primary key', 'unique' => '1', 'columns' => 'id')
);
synctable(db_prefix("rpalignment"), $rpdesc);
« Last Edit: July 22, 2012, 07:22:25 AM by Boris735 » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
$100 raised this year
Your help is greatly appreciated!
Who's Online
18 Guests, 0 Users
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search