Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grant table using php

Status
Not open for further replies.

dagoat10

Programmer
Jun 3, 2010
74
0
0
US
i was trying to use php to execute a grant create command for mysql, but it did not fill the grant table. Here is what i tried:

Code:
mysql_query("Grant create to $user . '@localhost'");

prior to this the user has been created, so what i am doing wrong?
 
query should be

Code:
mysql_query("GRANT CREATE ON DATABASENAME.* TO {$user}@localhost");

 
Its also a good idea to ask mysql for any errors it may be spitting out. Helps when debugging.

Code:
mysql_query(...)[red] or die(mysql_error())[/red];






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
it still did not set up a grant for the user
 
oh well.

we might have been able to help but you provide such a lack of information that it is impossible to do so.
 
yeah i did and it said can't find matching row in user table.

what i tried doing is creating the user then give him that grant on a specific database, but it does not go through
 
ok,

here is the senerio,

A user tries to long in to the database, if the user does not exist they must register, which means there name goes into the user table in mysql database. in order to use all the feature of the database i need to grant them access, but i don't want to do that everyday, if i can have that happen when the click the sumbit button on the registration page then it saves me the trouble of having to set up the grant table for each user

i do the following:

Code:
$query = "INSERT INTO user (Host, User, Password)
          VALUES('127.0.0.1', '$username', '$password')";
mysql_query($query) or die(mysql_error());

After that has excuted then i try this:

Code:
$query2 = "GRANT CREATE ON Fantasy_Football_2010.* TO {$username}@{$dbhost}";
mysql_query($query2) or die(mysql_error());

the second code is what returns:
Can't find any matching row in the user table

so what should i do?
 
then the user is not being created.

why are you trying to set up users on a mysql database using php?

of course you need to ensure that the user under whose credentials you are connecting to the database in order to perform these privilege updates has the requisite authority to do so.

in general, these kind of activities are managed via shell scripts. if you are trying to duplicate such things then ask whether it is really worth it. consider using something like webmin, usermin, plesk, cpanel etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top