Advertisement:

Author Topic: Mods can't create tables in MYSQL database  (Read 24362 times)

Offline karlbenson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,629
  • Gender: Male
    • Criminal Brief UK
Re: Mods can't create tables in MYSQL database
« Reply #20 on: April 30, 2008, 02:03:15 PM »
RSW686, The install file that I'm using it in can be done via ssi (AND using sqlite).

I think it might need
At the top of your page (after the including ssi.php bit)

Add
Code: [Select]
// Make sure we have access to install packages
if(!array_key_exists('db_add_column', $smcFunc))
db_extend('packages');

// Globals
global $db_prefix;

Btw I've attached the exact install file that I'm using (and just tested on b3p and works)

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Mods can't create tables in MYSQL database
« Reply #21 on: April 30, 2008, 02:14:08 PM »
Ah the db_extend('packages'); is what I needed to add. I was able to create a table without a problem.

You don't need the $db_prefix global anymore with SMF 2 functions. It parses out {db_prefix} itself and doesn't need {$db_prefix}.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline karlbenson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,629
  • Gender: Male
    • Criminal Brief UK
Re: Mods can't create tables in MYSQL database
« Reply #22 on: April 30, 2008, 02:28:12 PM »
Probably. ;)

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #23 on: April 30, 2008, 07:14:29 PM »
Don't really understand all that much, but are you saying that there IS a problem with SMF table creations?

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #24 on: April 30, 2008, 08:20:00 PM »
My mod can create tables in MySQL and SQLite (haven't tested Postgre yet). So I don't think the problem is with the functions.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline karlbenson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,629
  • Gender: Male
    • Criminal Brief UK
Re: Mods can't create tables in MYSQL database
« Reply #25 on: April 30, 2008, 08:38:09 PM »
Don't really understand all that much, but are you saying that there IS a problem with SMF table creations?

Not in smf no.  Its just some mods, might not be creating them properly due to not knowing the full way to create them.

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #26 on: April 30, 2008, 08:54:14 PM »
Don't really understand all that much, but are you saying that there IS a problem with SMF table creations?

Not in smf no.  Its just some mods, might not be creating them properly due to not knowing the full way to create them.

Aah, ok. Do you have a SMF 2 mod that requires table? So that I can test if your does work.

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Mods can't create tables in MYSQL database
« Reply #27 on: April 30, 2008, 09:26:36 PM »
Btw I've attached the exact install file that I'm using (and just tested on b3p and works)

One thing about your attached file. You are setting the default value with

'default' => 0

Take a look at the table after creation and notice the default value is not set. You need to set it with

'default' => '0'

as the SMF function checks it against null

      elseif (isset($column['default']) && $column['default'] != null)
         $default = 'default \'' . $column['default'] . '\'';

Just pointing this out as I just ran into it converting the table creation over for my mod.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #28 on: May 02, 2008, 09:58:31 AM »
Aah, ok. Do you have a SMF 2 mod that requires table? So that I can test if your does work.
Here's mine:

Code: [Select]
$smcFunc['db_create_table']('pretty_topic_urls', array(
array('name' => 'id_topic', 'type' => 'mediumint'),
array('name' => 'pretty_url', 'type' => 'varchar', 'size' => 80),
), array(
array('type' => 'primary', 'columns' => array('id_topic')),
array('type' => 'unique', 'columns' => array('pretty_url')),
));

$smcFunc['db_create_table']('pretty_urls_cache', array(
array('name' => 'url_id', 'type' => 'varchar', 'size' => 255),
array('name' => 'replacement', 'type' => 'varchar', 'size' => 255),
), array(
array('type' => 'primary', 'columns' => array('url_id')),
), array(), 'overwrite');

Or if you want the full mod: http://custom.simplemachines.org/mods/index.php?mod=636
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #29 on: May 02, 2008, 11:28:38 AM »
Quote
    * Database modifications
          o Creating the pretty_topic_urls table
          o Fixing any old topics with broken quotes
          o Creating the pretty_urls_cache table
    * Adding the default filters
    * Adding some settings
    * Running maintenance tasks
          o Updating the array of actions
          o Fix old boards which have broken quotes
          o Update board URLs
          o Update the filters

The package was installed successfully. You should now be able to use whatever functionality it adds or changes; or not be able to use functionality it removes.

www.tm-belgium.info

As you can see, doesn't work on my forum. Wth is rong...  :'(

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #30 on: May 02, 2008, 11:30:51 AM »
I am using MYSQL 5, can that be it?

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #31 on: May 02, 2008, 10:09:28 PM »
Well that looks like it worked... again, nothing in the error log?

MySQL 5 should be fine.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #32 on: May 03, 2008, 04:02:35 AM »
Well that looks like it worked... again, nothing in the error log?

MySQL 5 should be fine.

You say it looks like it worked, are you sure. Your mod works? I don't eaven know what you pretty url mod does with the url's.

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #33 on: May 03, 2008, 09:12:27 AM »
Well if there had been a PHP error that page would not have displayed correctly like that. Can you check in phpMyAdmin to whether the tables exist or not?

What the mod does is rewrite the URLs. That's not important though for checking whether the tables installed...
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #34 on: May 03, 2008, 11:20:46 AM »
Well if there had been a PHP error that page would not have displayed correctly like that. Can you check in phpMyAdmin to whether the tables exist or not?

What the mod does is rewrite the URLs. That's not important though for checking whether the tables installed...

Nope, no tables. It's so strange.

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #35 on: May 03, 2008, 10:56:50 PM »
Can you make tables with phpMyAdmin using the same account your forum does?
Try this query:
Code: [Select]
CREATE TABLE IF NOT EXISTS smf_pretty_topic_urls (
`ID_TOPIC` mediumint(8) NOT NULL default '0',
`pretty_url` varchar(80) NOT NULL,
PRIMARY KEY (`ID_TOPIC`),
UNIQUE (`pretty_url`))
« Last Edit: May 03, 2008, 11:00:51 PM by Dannii »
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #36 on: May 04, 2008, 03:56:18 AM »
Can you make tables with phpMyAdmin using the same account your forum does?
Try this query:
Code: [Select]
CREATE TABLE IF NOT EXISTS smf_pretty_topic_urls (
`ID_TOPIC` mediumint(8) NOT NULL default '0',
`pretty_url` varchar(80) NOT NULL,
PRIMARY KEY (`ID_TOPIC`),
UNIQUE (`pretty_url`))

Yep, that works just fine. Table is there when I do this.

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #37 on: May 04, 2008, 04:50:53 AM »
Just to confirm, you could do so using the MySQL account that SMF uses, and not a MySQL admin account?
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Jelle Mees

  • Jr. Member
  • **
  • Posts: 140
Re: Mods can't create tables in MYSQL database
« Reply #38 on: May 04, 2008, 07:42:07 AM »
Just to confirm, you could do so using the MySQL account that SMF uses, and not a MySQL admin account?

My host is servage.net, when I create a database, I can only create one user, and that user has full rights.
When I create servage mysql database I have:
- server
- databasename
- user
- password

That's it. So yeah, it's the same account I used for the SMF installation...

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Mods can't create tables in MYSQL database
« Reply #39 on: May 05, 2008, 12:27:39 PM »
Can you turn on database debugging and then check the queries when you are installing a mod?
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."