EchoFool Posted December 23, 2013 Share Posted December 23, 2013 (edited) Hey I have a query that looks like this: GRANT FILE ON [dbName].* TO '[user]'@'127.0.0.1' IDENTIFIED BY '[password]' WITH GRANT OPTION But i get this error: SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user '[hidden]'@'localhost' (using password: YES) Why is this happening? In Cpanel the user has all privalages yet FILE is not one of them and i cannot seem to grant it either =/ Here is my code: $dsn = 'mysql:dbname=hidden;host=127.0.0.1'; $user = //hidden $password = //hidden try { $pdo = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); exit; } $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //grant file permission temporarily $stmt = $pdo->prepare("GRANT FILE ON [hidden].* TO '[hidden]'@'127.0.0.1' IDENTIFIED BY '[hidden]' WITH GRANT OPTION"); try { $stmt->execute(array(1)); } catch (PDOException $e) { echo $e -> getMessage(); exit; //ERROR IS HERE } Where am i going wrong here? p.s i have used [hidden] solely for this post, the script does have the real login credentials Edited December 23, 2013 by EchoFool Quote Link to comment https://forums.phpfreaks.com/topic/284904-grant-file-privalage-then-remove-it-to-a-user/ Share on other sites More sharing options...
Solution kicken Posted December 23, 2013 Solution Share Posted December 23, 2013 (edited) You can't have a user that doesn't have a particular privilege grant itself that missing privilege. You need to use a user which has that ability and the ability to grant privileges in order to grant it. Typically this means you have to use the root user. I'm not that familiar with cpanel but if you can't grant it through there, and don't have direct access to the mysql root user then your host probably doesn't allow that privilege. If you are infact trying to grant a privilege across users rather than the same user (as your code reads), then make sure the source user has all the necessary privileges and the ability to grant. Edited December 23, 2013 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/284904-grant-file-privalage-then-remove-it-to-a-user/#findComment-1462988 Share on other sites More sharing options...
EchoFool Posted December 23, 2013 Author Share Posted December 23, 2013 Well i plan to run the script as a cron job anyway so i guess i could just use root user instead ! Quote Link to comment https://forums.phpfreaks.com/topic/284904-grant-file-privalage-then-remove-it-to-a-user/#findComment-1462989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.