我想知道共享主机是否通常会向其用户授予对该表的访问权限。
依靠它从脚本中快速获取当前数据库结构是否可以?
我的想法是使用此信息来净化输入,哈哈。例如: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/