News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Mod Authors: SMF 2.0 Database Functions

Started by SleePy, February 21, 2008, 05:57:21 PM

Previous topic - Next topic

[SiNaN]

It will be working just like you said in SMF 2.0 RC2. ;)
Former SMF Core Developer | My Mods | SimplePortal

SoLoGHoST

Ok, thanks [SiNaN], will place the code on standby mode so it's a quick copy and paste whenever RC2 is released.

Cheers :)

SAFAD

This Doesn't Work For Me
When I Make SmcFunc A Global
It Says Db_Query Is Undefind
And This In QueryString.php File
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

Please, keep that discussion to its own topic.

As I told you repeatedly in that topic the reason it doesn't work is because at the point the output buffer is being called, $smcFunc has NOT been defined thus you can make it global but you can't bring into local scope a variable that HASN'T been defined.

SAFAD

I Really Really Don't Understand A Single Word
i Can't Free Up My Mind To understand :(
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

Essentially what you're doing is:

function add1() {
  global $i;
  $i['var']++;
}

add1();
$i = array();
$i['var'] = 1;


$i hasn't been declared by the time add1 is called.

SAFAD

OOOOOOOOOO
Some Examples For Idiots Like Me :)
Yeah But Your Example Made Me Understand
Thx Chief ;)
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

SoLoGHoST

I am about to release a mod, but before I do, I'd rather not waste aweek waiting for the Customization Team to let me know that it isn'tusing all of the new Database Functions.  Reason is that this mod isfor RC1.2 and RC1.2 does not support unsigned integers.  So I need theintegers to be unsigned in order for the mod to work properly as ituses the entire maximum of the unsigned integers.  My question is:  CanI submit this mod using the old database functions and expect to haveit approved, since unsigned integers are necessary in order for the modto function properly??

Ofcourse, I've seen this fixed in RC2already, so I would definitely have to upgrade the mod using all of thenew database functions once RC2 is out.

Fustrate

I'd personally wait for RC2, and let us test it on the corrected DB functions :)
Steven Hoffman
Former Team Member, 2009-2012

SoLoGHoST

Ok, so I should wait for RC2 then?  No problem, will do.  I'm sure it would look a lot better in RC2 anyways.

Thanks Fustrate!  Big Time Saver!  But how long of a wait are we talking about??  Ok Ok, I'm on a Need-To-Know basis, I know, and I don't need to know.  It's all good.  Just hope it's going to be sooner, rather than later...

Garou

Running into a small problem with RC2

To create a table, traditionally I would use a line like...

$smcFunc['db_create_table']('table_name', $columns, $indexes, array(), 'update_remove');

However in RC2 this puts the table in the forum database as "table_name" instead of "smf_table_name". I'm assuming that {db_prefix} needs to be inserted there someplace but what would be the proper syntax?

SoLoGHoST

Quote from: Garou on October 13, 2009, 11:05:51 PM
Running into a small problem with RC2

To create a table, traditionally I would use a line like...

$smcFunc['db_create_table']('table_name', $columns, $indexes, array(), 'update_remove');

However in RC2 this puts the table in the forum database as "table_name" instead of "smf_table_name". I'm assuming that {db_prefix} needs to be inserted there someplace but what would be the proper syntax?

Yeah, this was 1 of the first things I noticed, need to use {db_prefix}.  Here's an example:
$smcFunc['db_create_table']('{db_prefix}table_name', $columns, $indexes, array(), 'update_remove');

Garou

Thank you very much, kind sir.
And one more mod ready for when RC2 goes public  :)

Arantor

Yes, this was intentional. All of the other db functions required {db_prefix} but this didn't. Plus it also means the package manager can be used for true non SMF stuff.

Sordell Media

This is probably a stupid question, but just to confirm before I break something, if I'm wanting to query non-SMF tables from within SMF, would these still be the correct functions to use? In case its relevant, I'm wanting to add a custom block to SimplePortal, that will reference & display a members info in my RPG which is external to SMF. All tables are in the one database, though my RPG tables don't have the smf_ prefix that my SMF tables do.

Arantor

Yes, these would still be the functions to use, and specifically they have {db_prefix} in when querying them. That said, be careful between RC1.2 and RC2.

When using db_create_table (and db_insert ?), in RC1.2 you would specify just the table name and use 'no_prefix' in the parameters if you want without a prefix. In RC2 you have to be explicit.

You are recommended to leave db_prefix in generally though.

Fustrate

To access existing tables, just use something like

$result = $smcFunc['db_query']('', '
     SELECT *
     FROM table_name',
     array()
);


basically, don't use {db_prefix}
Steven Hoffman
Former Team Member, 2009-2012

Sordell Media

Awesome, thanks yet again for the quick responses :D

Joshua Dickerson

Is the values argument of $smcFunc['db_query']() documented anywhere?
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

vbgamer45

I had to search the source myself was curious about db query cause I never use the first argument

function smf_db_query($identifier, $db_string, $db_values = array(), $connection = null)
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: