php - 共享主机是否授予对 INFORMATION_SCHEMA 的访问权限?

标签 php mysql hosting information-schema

我想知道共享主机是否通常会向其用户授予对该表的访问权限。

依靠它从脚本中快速获取当前数据库结构是否可以?

我的想法是使用此信息来净化输入,哈哈。例如:UPDATE table SET field = ?

? 可以是一个参数(我正在使用 PDO),但是如果我想让 field 成为一个变量呢?由于 PDO 不支持,我可以使用信息模式中的数据来查明该列是否存在...

最佳答案

任何 MySQL 用户都可以访问 information_schema 上的 SELECT,因为用户必须能够阅读 information_schema 能够从他被授予访问权限的数据库中读取。

您可以通过在单个数据库中的单个表上创建一个仅具有 SELECT 权限的新用户来对此进行测试。用户将能够读取 information_schema 中与该数据库中已授权表相关的任何内容,但不能读取任何未授权的内容。

/* Create a new user with only SELECT on one db: */
GRANT SELECT ON newdb.* TO newuser@localhost IDENTIFIED BY 'passwd';

/* Login with that user and list databases */
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| newdb              |
+--------------------+

From the relevant documentation:

Each MySQL user has the right to access these tables, but can see only the rows in the tables that correspond to objects for which the user has the proper access privileges. In some cases (for example, the ROUTINE_DEFINITION column in the INFORMATION_SCHEMA.ROUTINES table), users who have insufficient privileges will see NULL.

关于php - 共享主机是否授予对 INFORMATION_SCHEMA 的访问权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10098514/

相关文章:

来自字符串的 Php 正则表达式 "deleting only one charactered words"

php - 将 IDX MLS 集成到网站中

Mysql根据连接表分割列值

我自己网站上的 R Shiny 应用

HEROKU: ps:scale web=1 Procfile 中没有定义此类进程类型 web

php - 将表列的数据递增 1 || mysql

java - 将 Java 代码翻译为 PHP 代码(13 行)

php - 如何在 foreach 循环的每次迭代中更改 post 值

php - 在 PHP 中自动生成唯一 id,我可以指定 id 的起始编号

java - 托管基于 Java 的 REST API 服务