I've searched and couldn't find enough info. I am working on connecting to an external DB from PN to implement an application within the .8 framework.
Using the DBConnection class I have run up some test code like this:
Code
$pnRender = new pnRender('extdb');
$output = '<br />Testing DBConnectionStack::getConnectionInfo<br /><br />';
DBConnectionStack::init('extdb');
$output .= 'after init extdb current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
DBConnectionStack::popConnection();
$output .= 'after pop current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
DBConnectionStack::pushConnection('extdb');
$output .= 'after push extdb current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
DBConnectionStack::popConnection();
$output .= 'after pop current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
$pnRender->assign('output', $output);
return $pnRender->fetch('dliqms_user_main.htm');
$output = '<br />Testing DBConnectionStack::getConnectionInfo<br /><br />';
DBConnectionStack::init('extdb');
$output .= 'after init extdb current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
DBConnectionStack::popConnection();
$output .= 'after pop current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
DBConnectionStack::pushConnection('extdb');
$output .= 'after push extdb current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
DBConnectionStack::popConnection();
$output .= 'after pop current is = '.DBConnectionStack::getConnectionDBName().'<br />';
$output .= 'stack is :<br />';
$output .= '0stackname= '.$GLOBALS['PNRuntime']['DB'][0]['alias'].'<br />';
$output .= '1stackname= '.$GLOBALS['PNRuntime']['DB'][1]['alias'].'<br />';
$output .= '2stackname= '.$GLOBALS['PNRuntime']['DB'][2]['alias'].'<br />';
$pnRender->assign('output', $output);
return $pnRender->fetch('dliqms_user_main.htm');
which gives ouput like this
Code
Testing DBConnectionStack::getConnectionInfo
after init extdb current is = extdb
stack is :
0stackname= default
1stackname= extdb
2stackname=
after pop current is = pn8dev
stack is :
0stackname= default
1stackname=
2stackname=
after push extdb current is = extdb
stack is :
0stackname= default
1stackname= extdb
2stackname=
after pop current is = pn8dev
stack is :
0stackname= default
1stackname=
2stackname=
after init extdb current is = extdb
stack is :
0stackname= default
1stackname= extdb
2stackname=
after pop current is = pn8dev
stack is :
0stackname= default
1stackname=
2stackname=
after push extdb current is = extdb
stack is :
0stackname= default
1stackname= extdb
2stackname=
after pop current is = pn8dev
stack is :
0stackname= default
1stackname=
2stackname=
So I can see that the external DB is added (pushed) on to the stack automatically during 'init' and as a result of a 'push'. To return to the default PN DB I have to 'pop' the external DB prior to pnRender closing for page presentation or I get errors as PN scripts look in the external DB for the pntables.
My questions are:
#1. Is there a method to resequence the connections so that the PN DB stays on top other than using a combination of pop and push which may get messy if we have more than 2 DB's open?
#2. Is the connection meant to be persistent so that we can pop and push as often as we like until actually closing the connection?
#3. Is there a method to close a connection?
#4. Is there an explanation of the connection stack apropos PN available ?
and I guess #5... OR am I barking up the wrong tree completely?
--
cheers
Tony
Marble Bay : PostNuke Dev Work
Wren/Maxwell : PostNuke Hosting
