編輯 /data/tag/sql.inc.php,新增連接配置:
// otherdb 外部資料庫連接配置
$sqltag['otherdb']['dbhost'] = '資料庫IP';
$sqltag['otherdb']['dbname'] = '資料庫名稱';
$sqltag['otherdb']['dbuser'] = '資料庫用戶名';
$sqltag['otherdb']['dbpwd'] = '資料庫密碼';
$sqltag['otherdb']['dbprefix'] = 'dede_'; // 表前綴
$sqltag['otherdb']['dblanguage'] = 'utf8'; // 或 gb2312
記住連接名稱 otherdb。
登入被調用空間控制面板 → 資料庫管理 → 添加訪問主機,填入調用方伺服器 IP。
使用 {dede:sql} 標籤,指定 appname 為連接名稱:
{dede:sql sql="SELECT * FROM dede_archives ORDER BY id DESC LIMIT 0,10" appname="otherdb"}
<a href="/plus/view.php?aid=[field:id/]">[field:title/]</a>
{/dede:sql}
安全提醒: 僅在受信任的內網或已授權 IP 間使用,避免暴露資料庫憑證。