Proper way to reference tables of other modules?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
skypanther

Proper way to reference tables of other modules?

Post by skypanther »

What is the proper way to reference a table from another module? For example, from within the NMS module, how would I properly reference the FEU propdefn table?

I guess the following could potentially lead to problems:

SELECT * FROM ".cms_db_prefix()."module_feusers_propdefn ORDER BY prompt

I can't imagine that module table names get changed that often, certainly not by normal installs.

Tim
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Proper way to reference tables of other modules?

Post by calguy1000 »

That'll work, as it's in the same database.

But with FEU, the preferred method would be to use the functions in FrontendUsers.ap.php

i.e:

$feu = $this->GetModuleInstance('FrontEndUsers');
$propdefn = $feu->GetPropertyDefn('PropertyName');
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
skypanther

Re: Proper way to reference tables of other modules?

Post by skypanther »

Thanks. In this case, I want to get a list of field values in the name column from the FEU propdefn table. So, I don't necessarily know which 'PropertyName' to use. Perhaps I should have been more specific with my query example. I'm using:

SELECT name, prompt FROM ".cms_db_prefix()."module_feusers_propdefn where type = 0 ORDER BY prompt

Sounds like I can just use the table's name directly without too much trouble.

Thanks,
Tim
Post Reply

Return to “Developers Discussion”