MyBB Community Forums

Full Version: [PLEASE HELP] Need PHP Code (MySQL Query) Create MySQL Account Remotely
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi

I am currently developing an Open-SourceBig Grin project and I need alittle code please, Could someone either post or PM me the code to allow Adding MYSQL User Accounts using a PHP MySQL Query.

Whoever submits the code ill give credit to, if you want your name or forum nick creditted just let me knowWink

I will talk more about the project when it comes close to release.

Many ThanksWink
http://dev.mysql.com/doc/refman/5.0/en/grant.html
GRANT ALL PRIVILEGES ON database.* TO 'root'@'localhost'
  IDENTIFIED BY 'password'
Can you please post the PHP Code, Thank You.
Maybe this tutorial is what you need as it contains the necessary queries: http://www.php-mysql-tutorial.com/mysql-...l-user.php
It's the PHP code I'm after please. Thank You.
mysql_query("GRANT ALL PRIVILEGES ON database.* TO 'root'@'localhost'
IDENTIFIED BY 'password'");

dude....Just put all mysql queries in the mysql_query("") function
mysql_query("GRANT ALL PRIVILEGES ON database.* TO 'root'@'localhost'
IDENTIFIED BY 'password'");

doesn't create the account.
You have changed the details right?
Change database to the database you want to grant permissions to, root is the username you want to create, localhost is the domain you wish to allow the user to access the db from, password is the password...

If you've changed that to meet your needs, then you might want to try the following, instead of doing the above GRANT statement. (got this from micaels link)
INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', 'user', PASSWORD('password'), 'Y', 'Y', 'Y');

EDIT: You might have to do the flush command after.... if you read the links we've provided there should be more than enough information. As Kimmo said, you should be able to stick any of these commands in mysql_query.
this is strage this doesnt work, ive spent hours and failed so far???

<?php
mysql_query("INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', 'user', PASSWORD('password'), 'Y', 'Y', 'Y')");
?>
<?php
mysql_connect('[b]db_host[/b]', '[b]db_user[/b]', '[b]db_password[/b]');
mysql_select_db('mysql');

$query = mysql_query("
	INSERT INTO user (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`)
	VALUES ('[b]user_host[/b]', '[b]user_name[/b]', PASSWORD('[b]user_password[/b]'), 'Y', 'Y', 'Y')");
if(!$query)
{
	print_r(mysql_error());
}
else
{
	mysql_query("FLUSH PRIVILEGES");
echo "finished";
}
?>
I know this works because I just made it.
You will need to change the things in bold to your details.
Pages: 1 2