1

I'm thinking about some database management system, and my question is simple :

Is there a simple and reliable way to retrieve the access rights (write, readonly etc.), by a PHP code?

I haven't wrote any code yet, as this is just in my mind for now, that will just help me to structure some tables.

RAS
  • 8,100
  • 16
  • 64
  • 86
BMN
  • 8,253
  • 14
  • 48
  • 80
  • http://dev.mysql.com/doc/refman/5.0/en/show-privileges.html – ZiTAL Feb 13 '12 at 13:39
  • 1
    http://dev.mysql.com/doc/refman/5.0/en/show-grants.html – vascowhite Feb 13 '12 at 13:41
  • Thanks @vascowhite, I just need some string parsing at this give a result like `GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY ...` but I can deal with it ;) – BMN Feb 13 '12 at 13:47

1 Answers1

2

All database permissions are stored in a default mysql database: information_schema. Simply create a MySQL user who has permissions to view entries in this table, and use this user's login credentials when connecting from a PHP script. You can the retrieve permissions from the various permissions tables (which include DB level, table level, and column level permissions) to report back user rights. Something like:

SELECT * FROM`information_schema`.`user_privileges` WHERE`grantee` LIKE"'user'%";

Once you've run this query you can format the results however you'd like in PHP.

Ben D
  • 14,321
  • 3
  • 45
  • 59