Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: gmc1 - tammikuu 22, 2014, 03:45:39 IP

Otsikko: DB calls using SMF connection?
Kirjoitti: gmc1 - tammikuu 22, 2014, 03:45:39 IP
I've been searching this site and the docs - and finding pieces of what I need... but missing something to tie it all together... Hoping you can point me in the right direction...

I have a new install of SMF 2.0.6 with SimplePortal and bridged to Coppermine.
I am trying to write/incorporate some custom code to be invoked from SimplePortal Blocks/Pages that need to access some non-SMF tables contained in the same MySQL database...

I could certainly use my own code to connect to the database, and query - but thought if I could take advantage of an (already existing?) connection, and use the SMF functions ($smcFunc['db_query'], etc) - that it would be less overhead... and I'd learn more about SMF along the way...

First - is this possible/recommended?
Second - Can you point me to some doc on what I need to do to invoke...

- Just calling the db_query function results in a 'hacking attempt' message...
- Trying to include SSI.php into the block code results in:
"Fatal error: Cannot redeclare ssi_shutdown() (previously declared in /home/domain/www/subdomain/SSI.php:201) in /home/domain/www/subdomain/SSI.php on line 203"

Long time user of PHP... Coppermine... New to SMF and Simple Portal.
Thanks!
Greg
Otsikko: Re: DB calls using SMF connection?
Kirjoitti: hadesflames - tammikuu 23, 2014, 12:49:52 IP
This is the documentation for smcFunc:

http://wiki.simplemachines.org/smf/$smcFunc (http://wiki.simplemachines.org/smf/$smcFunc)

There is nothing wrong with using it to access your db.
Otsikko: Re: DB calls using SMF connection?
Kirjoitti: gmc1 - tammikuu 23, 2014, 04:16:20 IP
Thanks for the reply...
I had found that doc... but still seems to be missing a piece to make it work...
Attempting to invoke $smcFunc['db_query'] from my Simple Portal block or page results in a 'hacking attempt' message... and it appears SSI.php is already included as attempts to include it again result in duplicate function definitions...

How do I 'condition' my environment to be able to use the SMF DB functions without triggering the 'hacking attempt' messages?  That message comes out from dozens of places...
I'd venture a guess that for the moment the error is coming from Subs-Db-mysql.php?

if (!defined('SMF'))
    die('Hacking attempt...');

But since I am in an SMF mod - I would have thought that would already be set?

Tried looking for other postings or doc before slugging through it with code updates to find the location.. :)
Otsikko: Re: DB calls using SMF connection?
Kirjoitti: Arantor - tammikuu 23, 2014, 04:57:57 IP
What query, *exactly* are you trying to run? There are times a query will generate a 'Hacking attempt' error.