I’ve just started playing with the loopDbChunk v1.2 snippet, but want it to get the table ’images’ from an external database. I’ve altered the code of LoopDBChunk.php (line 184 onwards) for the renderChunks() function.
function renderChunks()
{
global $modx;
require_once("Pagination.php");
$query = '';
$rs = '';
$output = $this->header;
$pageStart = $this->getPageStart();
if($this->sql != '')
{
$query = str_replace('_eq_', '=', $this->sql);
}
else
{
$fields = implode(',', array_unique($this->fieldNames));
$query = 'SELECT ' . $fields . ' FROM ' . $this->tableName;
if ($this->orderby != '') {
$query .= ' ORDER BY ' . $this->orderby;
}
}
$rs = $modx->db->connect('localhost', 'database', 'user', 'password', true);
$rs = $modx->db->query($query);
$numRows = $modx->db->getRecordCount($rs);
if($this->perPage > 0)
{
$from = $pageStart - 1;
$query .= ' LIMIT ' . $from . ', ' . $this->perPage;
}
However, now the whole page explodes
« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« Execution of a query to the database failed - SELECT command denied to user ’account_user’@’localhost’ for table ’cms_site_tmplvars’ »
SQL: SELECT tv.*, IF(tvc.value!=’’,tvc.value,tv.default_text) as value FROM `main_db`.`cms_site_tmplvars` tv INNER JOIN `main_db`.`cms_site_tmplvar_templates` tvtpl ON tvtpl.tmplvarid = tv.id LEFT JOIN `main_db`.`cms_site_tmplvar_contentvalues` tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = ’11426’ WHERE tv.name IN (’id’) AND tvtpl.templateid = 90
[Copy SQL to ClipBoard]
and on and on. So it looks like the connect to external db is being used by every aspect of this page and not just the chunk.
Any advice?
Cheers