Okay, I managed to get this working with a different database, using DBAPI connect() instead. I wasn’t able to use DBAPI select(), because it requires me to enter the table name (databasename.
tablename), which also has to be done in the query (’SELECT ’ . $fields . ’
FROM ’ . $this->tableName;). If I enter the tablename in both select() and query(), it fails...
Since I’m using connect() in this script, it will always connect to the database when I’m doing a query. Will this cause a heavy load on the server, and hows the safety? Are there any other methods that could do this job better?
Thanks again, guys! I’m really a designer more than a coder, but got stuck here doing this coding job... I’m learning though!
Here’s the new code:
function renderChunks()
{
global $modx;
$query = '';
$rs = '';
$output = '';
if($this->sql != '') {
$query = $this->sql;
}
else {
$fields = implode(',', $this->placeholders);
$query = 'SELECT ' . $fields . ' FROM ' . $this->tableName;
if ($this->orderby != '') {
$query .= ' ORDER BY ' . $this->orderby;
}
if ($this->limit != '') {
$query .= ' LIMIT ' . $this->limit;
}
}
// NEW CODE STARTS HERE
$rs = $modx->db->connect('localhost', '*** database ***', '*** username ***', '*** password ***', true);
// NEW CODE ENDS HERE
$rs = $modx->db->query($query);
$chunk = $modx->getChunk($this->chunkName);
while( $row = $modx->db->getRow($rs) ) {
$output .= $this->getChunkReplaced($row, $chunk);
}
return($output);
}