I’m currently trying to pull values for a Template Variable (Dropdown List) from an external database (which just so happens to be a MODx install as well). Both sites reside on the same server, and I’ve tried the following using a snippet and running it via the EVAL command.
Unfortunately I get the following error:
MODx encountered the following error while attempting to parse the requested resource:
« Failed to select the database ’bcetb_modx’! »
Is there a way to pull values from an external database into a template variable drop down list?
Snippet:
//$db = $modx->db->connect($host, $database, $uid, $pwd, true);
$db = new DBAPI();
$db->connect($host,$database, $uid,$pwd);
$result = $db->select('id, pagetitle','site_content');
if( $db->getRecordCount( $result ) >= 1 )
{
while( $row = $db->getRow( $result ) )
{
echo $row['id'].'||'.$row['pagetitle'];
}
}
//disconnect
$db->disconnect();
//reconnect to modx db
$modx->db->connect();
Template Variable:
@EVAL return $modx->runSnippet('etbDropdown');