tags:

views:

26

answers:

1

What query would I have to use to check if the querying user has permissions to create temporary tables in the database?

+1  A: 

I do not know if there is an elegant way of doing this with a query, but a "hackish" type of way to do it would be to use a mysql_query() and see if you get a result for that table or an error.

function checkCreateTempPermission($table) {
     $res = mysql_query("CREATE `$table` "); // modify this to be your temporary table code.
     if ($res === false) {
         if (strstr(mysql_error(), "command denied to user")) {
              return false;
         }else {
              // some other error happened not sure how you want to handle it so left blank.
         }
     }else {
         return true;
     }
}

I have not tested this at all, more or less a theory of how it could be done. Alternatively, you can write a script that runs this SQL:

Show grants for myuser;

And then loop through that testing if they have access for that table. This would take a bit more work, but at least would not error out. Hope that helps to get you started.

Brad F Jacobs
I guess I'll run with Show Grants.
Raj Sekharan