先在前臺測試連接數(shù)據(jù)庫,查詢數(shù)據(jù)成功后再進(jìn)行操作,記得先添加php擴(kuò)展
(pgsql不是管理員賬號一些操作會(huì)沒有權(quán)限 username: postgres)
$allow_column = Db::connection('plugin.admin.pgsql')
->select("SELECT column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name = '$table'");
if (!$allow_column) {
throw new BusinessException('表不存在');
}
$columns = array_column($allow_column, 'column_name', 'Field');
$allow_column = array_flip($columns);
if (!in_array($field, $columns)) {
$field = null;
}
$allow_column = Db::connection('plugin.admin.pgsql')
->select("SELECT column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name = '$table'");
if (!$allow_column) {
throw new BusinessException('表不存在', 2);
}
$columns = array_column($allow_column, 'column_name', 'Field');
$columns = array_flip($columns);