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

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
jdwork
Forum Members
Forum Members
Posts: 10
Joined: Sat Dec 23, 2006 7:03 pm

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

Post 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 
alby

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

Post 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
jdwork
Forum Members
Forum Members
Posts: 10
Joined: Sat Dec 23, 2006 7:03 pm

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

Post 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 :)
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

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

Post 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/>';
}
Last edited by Jos on Mon Nov 09, 2009 10:45 am, edited 1 time in total.
Post Reply

Return to “Developers Discussion”