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!
Access DB name within UDT?
Re: Access DB name within UDT?
You can access the config stuff like this:
However, if you're doing database operations you can just get a reference to the db object and run your query:
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.
Code: Select all
$config =& cmsms()->GetConfig();
Code: Select all
$db =& cmsms()->GetDb();
$result = $db->Execute('SELECT * FROM tablename WHERE id = ?', array('1'));