Ok I got this resolved
Just in case anyone wants to know, here's the code I used
function db_error($error) {
$fp = fopen("tpl/db_error.tpl", "r");
$tpl = fread($fp, filesize("tpl/db_error.tpl"));
fclose($fp);
$tpl = str_replace("{{error}}", $error, $tpl);
return $tpl;
}