By armanschwarz on
I added an install file with the following content to my block:
<?php
// $Id$
/**
* @file
* Creates or deletes the Database Tables required by the Ads Module
*
*/
function ads_install() {
//this function will create the database if it does not already exist
if ((!db_table_exists('ad_registrations'))) {
//the database does not exist, so it must be created
db_query('
CREATE TABLE {ad_registrations} (
uid int(10),
ad_providers VARCHAR(255),
provider_ids VARCHAR(65535),
active_zones VARCHAR(255),
zone_providers VARCHAR(255),
ad_ids VARCHAR(65535),
extra_data VARCHAR(65535),
PRIMARY KEY (uid)
)
');
}
}
function ads_uninstall() {
//this function deletes the ad_registrations database
if ((db_table_exists('ad_registrations'))) {
//the database exists, so remove it
db_query('DROP TABLE {ad_registrations}');
}
}
?>
(without the ?> ofcourse) but for some reason the table doesn't get created when I activate the module, and it doesn't appear in the uninstall tab. Any idea why this would be happening? I get no syntax errors when installing / running the module. Do I need to call this file somewhere? The file is called ads.install (module file is ads.module)
Comments
just some general ideas. I
just some general ideas. I would test two things:
1. did you test run the create script directly in db?
2. I'll also try without db_table_exists condition first
also beware, once a module is installed, it won't run install script again, unless it's first disabled (unselected) AND uninstalled (on the top of module list page)
The query executes without
The query executes without problems. If I can't install it again without uninstalling it first, that would explain why the install script isn't running anyway, but what about the uninstall script? Why does drupal not recognise I have an uninstall function? In regards to the 'IFs', I could take them out but it doesn't really explain why the module isn't found at all in the uninstall tab..
open table "system", look
open table "system", look for your ads module entry, play with schema_version and see if it helps. that's how i got mine work a while back. good luck.
ah, great that should get me
ah, great that should get me going. Thanks for the help.
ok so I've simplified my
ok so I've simplified my code a bit:
I removed the reference to the module in the system table, and now the database installs properly, but the module still isn't showing up in the uninstall list...??
You must first disable and
You must first disable and then the module will show up in the list of uninstallable modules.
Regards
Werner
I did that several times,
oh right, thanks. Learn something new every day...
how .install file works??
just read and follow steps for .install file
http://learningdunia.com/blog/how-create-tables-using-custom-module-or-w...