While using an already established mysqli connection to a MySQL database from PHP, I'm looking for a simple way to check if this connection (i.e. the authenticated user for this connection, if any) has some desired access to a certain table (or at least any access to the table whatsoever).
If it matters, the table in question is in another database than the currently
USED one, and I'm trying to access it by the following kind of query:
SELECT * FROM some_other_database_on_the_same_server_as_the_currently_used_database.some_table WHERE id = 1
My research so far has only found the ridiculously complex solution of manually parsing and resolving the depressingly messy raw-string output of the
SHOW GRANTS command, which I just cannot accept being the only way of doing this!?
Things I have tried (and failed) so far are the following:
To simply perform the desired operation in question against the table in question, and evaluate the error codes if it fails. To my big surprise, a
SELECT query (issued e.g. with the
mysqli_query() API) simply returns
False if I don't have the appropriate permissions for the table in question, without any error code or error message being reported at all (inspected both manually in the debugger on the connection object and by means of the
mysqli_error() API). The problem with this is that
False will also be returned if e.g. the queried table doesn't exist at all, so I cannot know from this if it failed because of permission problems or because of something completely different.
To search for some kind of equivalent of the
HAS_PERMS_BY_NAME command of Microsoft SQL Server, which I always come up empty-handed with though, consistently just being politely herded back by Google to the extremely clumsy
SHOW GRANTS command of MySQL.
So my question is, again:
How can I, with no holds (or hacks) barred, check if my mysqli connection has some desired access (or at least read access if nothing else) to a certain MySQL table?
There really must be some easy way of doing this, right?