Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: jjsmith - lokakuu 16, 2013, 01:56:18 AP

Otsikko: Need help with smcFunc['db_create_table']
Kirjoitti: jjsmith - lokakuu 16, 2013, 01:56:18 AP
Hi,

I'm running a command-line script in which I want to use smcFunc['db_create_table'](...) to create a table.

However, i get the error "Notice: Undefined index: db_create_table in ...."

I did a var_dump($smcFunc) and sure enough, none of the "Database Package Functions" (listed here -http://wiki.simplemachines.org/smf/$smcFunc) are in the $smcFunc variable.  Only the db_query, db_fetch_row, etc are there.

I include the following files in my php script:
require('../SSI.php');
include('../Sources/DbPackages-mysql.php');

DbPackages-mysql.php is where db_create_table is defined, but that doesn't update $smcFunc.

Is there something else I need to include or something I need to execute?  It might even be a php thing vs smf thing...

Thanks,
Josh




Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: andershz - lokakuu 16, 2013, 02:06:08 AP
Try db_extend('packages');
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: jjsmith - lokakuu 16, 2013, 02:24:28 AP
That's the ticket!

Thanks andershz!  Made my day.  Progress is definitely now at hand.

For my edification - do you know of any official smf documentation about that?

Josh
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: andershz - lokakuu 16, 2013, 04:07:56 AP
There is, but not easy to find:
http://dev.simplemachines.org/smcfunctions.php

I also think the text is misleading:

Database Package functions were also introduced in SMF 2.0. These special functions allow customization creators to easily modify a database that will support multiple database types. The below functions only exist when using db_extend('packages');. By Default this is automatically called in the Package Manager.

I interpret that as the extra functions should always be available when installing a mod, but apparently "in the Package Manager" means something else.
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: emanuele - lokakuu 16, 2013, 05:16:03 AP
As far as I remember it is, but the OP is using SSI (at least from the code he posted).

About documentation, you can take a look at:
http://wiki.simplemachines.org/smf/$smcFunc (http://wiki.simplemachines.org/smf/$smcFunc)

ETA: fixed link.
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: andershz - lokakuu 16, 2013, 07:39:54 AP
You remember correctly, I forgot about the SSI bit.

The $smcFunc wiki link is good, but it doesn't mention that db_extend is needed for the Database Package Functions, (when using SSI).
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: emanuele - lokakuu 16, 2013, 07:48:58 AP
There is an "edit" button over there, you can add it. :P ;)
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: andershz - lokakuu 16, 2013, 08:10:18 AP
Lainaus käyttäjältä: emanuele - lokakuu 16, 2013, 07:48:58 AP
There is an "edit" button over there, you can add it. :P ;)

Done.
Otsikko: Re: Need help with smcFunc['db_create_table']
Kirjoitti: emanuele - lokakuu 16, 2013, 08:20:18 AP
Great, thanks! :)