Page 1 of 1

call a udt from a udt (reuse a dbconnect user defined tag in a user defined tag)

Posted: Fri Nov 06, 2009 6:59 pm
by jdwork
I searched for calguy1000's example as stated in other post but did not find it.

  I use the news module to display pages generated by UDTs. (Kids parents, kids birthday, kids favorites, Kids siblings)  I though it a rather clever idea.  Now, I am trying out virtualmin, on another server, and virtualmin creates a single db for everything, so after moving I have to update a bunch of db connection names at the beginning of each UDT.  Ideally I would insert a db UDT {mydatabaseconnection} at the start of each display UDT {kidsbirthdays} and so only have to update {mydatabaseconnection} if I switch db or username etc.

  I have experimented with literals, links to scripts and looked for a db connect tag, but have so far been unsuccessful.

Thank you 

Re: call a udt from a udt (reuse a dbconnect user defined tag in a user defined tag)

Posted: Fri Nov 06, 2009 7:05 pm
by alby
jdwork wrote:   I use the news module to display pages generated by UDTs.
??

jdwork wrote: .... so after moving I have to update a bunch of db connection names at the beginning of each UDT.
Why you not use same DB connect of CMSMS (you have mysql data in config.php only)
Look in Documentation for Share your UDT for DB example

Alby

Re: call a udt from a udt (reuse a dbconnect user defined tag in a user defined tag)

Posted: Mon Nov 09, 2009 9:34 am
by jdwork
:-[ Yes, using the same config would remove that redundancy wouldn't it. 

Could it be as simple as:

Code: Select all

$dbconnect = mysql_connect($db_hostname,$db_username,$db_password);
. . .
mysql_select_db("studentdb", $con);

Maybe it'll also fix my error.

Code: Select all

cmsmadesimple  string(61) "Smarty error: unable to read resource: "globalcontent:footer"" string(61) "Smarty error: unable to read resource: "globalcontent:footer"" 
I upgraded from php4 to 5 and mysql 4 to 5 and cmsms 1.5 to current.  Everything went sweet until I try to insert into a table.  I insert fine but that ugly error pops up.

I will get back to this later in the week.

Thanks Alby :)

Re: call a udt from a udt (reuse a dbconnect user defined tag in a user defined tag)

Posted: Mon Nov 09, 2009 10:11 am
by Jos
You can use something like

Code: Select all

global $gCms;
$db = &$gCms->db;

$query = "SELECT * FROM ".cms_db_prefix()."yourtablename WHERE category = ?";
$dbresult = $db->Execute($query, array($categoryid));

if( $dbresult )
{
   while ($row = $dbresult->FetchRow())
   {
      ...
   }
}
else
{
   echo 'DB error: '. $db->ErrorMsg().'<br/>';
}