How can I grant MySQL permissions from inside PHP?
what is the syntax to execute this statement in php page-
grant file on *.* to kentest@localhost identifie开发者_如何学God by 'kentest1';
Check your [MySQL?] database vendors documentation - because that's a DBMS statement, not PHP. I'd start here: http://php.net/manual/en/function.mysql-connect.php
EDIT: To clarify, assuming you get your connection working, it would be as simple as wrapping your query in a call to mysql_query()
. Example:
mysql_connect(...);
mysql_select_db(...);
mysql_query("grant file on *.* to kentest@localhost identified by 'kentest1';");
- Check out the GRANT command! http://dev.mysql.com/doc/refman/5.1/en/grant.html
- Check out the CREATE USER command! http://dev.mysql.com/doc/refman/5.1/en/account-management-sql.html
Ultimately check out the all section about account management in MySQL: http://dev.mysql.com/doc/refman/5.1/en/account-management-sql.html
firstly,you check the user of mysql_connect,is a root? this user must have the right to grant.
Here's some basic code that will work for many MySQL queries, including GRANT so long as the user is permissioned to do so:
// Credential variables, separated so we can reuse them later
$host = "localhost";
$user = "user";
$pass = "123456notsecure";
$db = "database_to_use";
// Set up the query we're going to run
$query_to_run = "QUERY TO RUN";
// Make the MySQL connection
$mysql_connection = mysql_connect($host, $user, $pass);
// Select the database to use
mysql_select_db($db) or die(mysql_error());
// Run the query
$result_of_query = mysql_query($query_to_run) or die('Running the query failed: ' . mysql_error());
// Close the MySQL connection
mysql_close($mysql_connection);
精彩评论