Mods can't create tables in MYSQL database

Started by Jelle Mees, April 26, 2008, 08:07:38 PM

Previous topic - Next topic

karlbenson

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
// 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)

rsw686

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

karlbenson


Jelle Mees

Don't really understand all that much, but are you saying that there IS a problem with SMF table creations?

Dannii

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."

karlbenson

Quote from: Jelle Mees 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?

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

Jelle Mees

Quote from: karlbenson on April 30, 2008, 08:38:09 PM
Quote from: Jelle Mees 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?

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.

rsw686

Quote from: karlbenson on April 30, 2008, 02:03:15 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

Dannii

Quote from: Jelle Mees on April 30, 2008, 08:54:14 PMAah, ok. Do you have a SMF 2 mod that requires table? So that I can test if your does work.
Here's mine:

$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."

Jelle Mees

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...  :'(

Jelle Mees


Dannii

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."

Jelle Mees

Quote from: Dannii 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.

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.

Dannii

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."

Jelle Mees

Quote from: Dannii 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...

Nope, no tables. It's so strange.

Dannii

#35
Can you make tables with phpMyAdmin using the same account your forum does?
Try this query:
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`))
"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."

Jelle Mees

Quote from: Dannii on May 03, 2008, 10:56:50 PM
Can you make tables with phpMyAdmin using the same account your forum does?
Try this query:
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.

Dannii

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."

Jelle Mees

Quote from: Dannii 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?

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...

Dannii

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."

Advertisement: