Page 1 of 1

Access DB name within UDT?

Posted: Sat May 07, 2011 6:29 pm
by donia
Is there a simple way to access the database name, username, and password from within a UDT? I have many UDTs that need access to the database, and right now I'm manually assigning the database name to a variable. $DBName = "mydbname";

The database name (and username and password) must be stored in a global somewhere, and I would like to just be able to access that.

Thank you!

Re: Access DB name within UDT?

Posted: Mon May 09, 2011 10:11 am
by tomgsd
You can access the config stuff like this:

Code: Select all

$config =& cmsms()->GetConfig();
However, if you're doing database operations you can just get a reference to the db object and run your query:

Code: Select all

$db =& cmsms()->GetDb();
$result = $db->Execute('SELECT * FROM tablename WHERE id = ?', array('1'));
Best place to find more info on how to do this is by looking at code in other modules, News would be a good place to start.