Page 1 of 1

How to grant privileges to a mysql user by using php?

Posted: Thu Nov 06, 2008 6:52 am
by mehtab_hu
How to grant privileges to a mysql user by using php.
I work on a php project where I can
1: Create database by using php script.
2: Create user in mysql by using php script.
3: Grant access to user for the specific database by using php script.
Problem is in step no 3.
I need to know how can grant access to user for a specific database by using php script, where the user has full access control on has database but the other database should not accessible.

Need some privileges techniques overcome the above problem.
If any one have knowledge about the privileges then please help me!
Thank
Best regard

Re: How to grant privileges to a mysql user by using php?

Posted: Thu Nov 06, 2008 9:30 am
by onion2k
It's just an SQL query like any other. Use mysql_query("GRANT blah blah blah").. Obviously the user you connect to MySQL with will need to have the GRANT privilege.

Re: How to grant privileges to a mysql user by using php?

Posted: Thu Nov 06, 2008 9:34 am
by VladSun
In fact, using the GRANT query will create the user specified if it's not existing. So Step 2 can be omitted.

Re: How to grant privileges to a mysql user by using php?

Posted: Thu Nov 06, 2008 9:37 am
by onion2k
VladSun wrote:In fact, using the GRANT query will create the user specified if it's not existing. So Step 2 can be omitted.
I'd still do it anyway otherwise the user will be created without a password..

Re: How to grant privileges to a mysql user by using php?

Posted: Thu Nov 06, 2008 9:40 am
by VladSun
I don't think so. At least it will not happen with a proper GRANT query:
[sql] GRANT    ALLON    mydatabase.*TO    myuser@myhostIDENTIFIED BY    'mypassword' [/sql]

Re: How to grant privileges to a mysql user by using php?

Posted: Fri Nov 07, 2008 12:43 am
by mehtab_hu
Hi VladSun & onion2k!
Thanks for helping!
My script is working now.
Best Regard.