先在前台测试连接数据库,查询数据成功后再进行操作,记得先添加php扩展
(pgsql不是管理员账号一些操作会没有权限 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);