Jump to content

Make new user database in php how.


redarrow

Recommended Posts

Is there a way to get php to make a new user account in mysql and only allowing that new account have the amount of databases i say so.


For an example a user choose a package joins my host site, The user gets the new database account info name and password and amount of database allowed.

How do i go around to set this up cheers.




Is this possable to make new user in a mysql database in php code (name: password:?

Is it possable to only let total amount of databases used from that user account?


ADVANCE THANK YOU.

PS. if you got any links/tutorals on mysql php interfaces to do this then please post them cheers.




[b]Is this the correct way to make a new user in mysql cheers.[/b]

I thnk this is command line how to do it in php .

or can you insert stright to the user folder to make the new account directly from php.

[code]

INSERT INTO user (host,user,password) VALUES('%','username_r',PASSWORD('password'));
INSERT INTO user (host,user,password) VALUES('%','username_w',PASSWORD('password'));
INSERT INTO user (host,user,password) VALUES('%','username',PASSWORD('password'));

[/code]
Link to comment
Share on other sites

In phpmyadmin under mysql database you got the below tables for user.

i need to no if i made an insert into this database user table it should make a new user for the mysql database and then that user can have there own mysql account.

Afther the user post there informtion know that user can use there own mysql database connection they made am i write please tell me.

Thank you.

[code]
Host
User
password
Select_priv
Insert_priv
Update_priv
Delete_priv  
Create_priv
Drop_priv
Reload_priv
Shutdown_priv
Process_priv  
File_priv
Grant_priv
References_priv
Index_priv
Alter_priv  
Show_db_priv
Super_priv
Create_tmp_table_priv
Lock_tables_priv  
Execute_priv
Repl_slave_priv
Repl_client_priv
ssl_type  
ssl_cipher
x509_issuer  
x509_subject  
max_questions
max_updates
max_connections
[/code]
Link to comment
Share on other sites

Not tested this yet but should enter the coorrect info to the database to make a new mysql connection for users that join my hosting service.

So that the users can have there own mysql connection.

If you wanted to kindly go over the code and see if its correct thank you.

[b]
Do not use this code unless you no what your doing you could muck your mysql up cheers.[/b]

[code]

<?

// Script begining.

// Connect to the mysql database for the admin.


$sql_host =   'localhost';  //add host information
here (localhost, mysql.host.com, etc.)
$sql_un   =   'xxxxxxx';  //add your user name here
$sql_pass =   'xxxxxxx';  //add your password here
$sql_db   =   'mysql';  //add your database name
here
$sql_tbl  =   'user';  //add your  table name
here

mysql_connect("$sql_host", "$sql_un", "$sql_pass") or
    die ("Could not connect to database");
mysql_select_db($sql_db) or
    die ("Could not select database");






// check if mysql connection new name and password
exists.

$tmp=mysql_query("SELECT * FROM user WHERE id = '$id'");

if(! $user==1) {

echo" Your mysql connection name and password already

exists";

echo"<br><br>";

echo"If there is a problam please email admin <br>

<a href='http://www.what-ever.com/contactus.php'>Email admin</a>";

}




// Post all the varables to insert.

$Host=$_POST["Host"];
$User=$_POST["User"];
$password=$_POST["password"];  
$Select_priv=$_POST["Select"];  
$Insert_priv=$_POST["Select_priv"];
$Update_priv=$_POST["Update_priv"];  
$Delete_priv=$_POST["Delete_priv"];  
$Create_priv=$_POST["Create_priv"];
$Drop_priv=$_POST["Drop_priv"];
$Reload_priv=$_POST["Reload_priv"];  
$Shutdown_priv=$_POST["Shutdown_priv"];
$Process_priv=$_POST["Process_priv"];  
$File_priv=$_POST["File_priv"];
$Grant_priv=$_POST["Grant_priv"];  
$References_priv=$_POST["References_priv"];
$Index_priv= $_POST["Index_priv"];
$Alter_priv =$_POST["Alter_priv "];  
$Show_db_priv=$_POST["Show_db_priv"];
$Super_priv= $_POST["Super_priv"];
$Create_tmp_table_priv =$_POST["Create_tmp_table_priv"];
$Lock_tables_priv =$_POST["Lock_tables_priv"];  
$Execute_priv=$_POST["Execute_priv"];
$Repl_slave_priv =$_POST["Repl_slave_priv"];
$Repl_client_priv=$_POST["Repl_client_priv"];
$ssl_type =$_POST["ssl_type"];  
$ssl_cipher =$_POST["ssl_cipher"];
$x509_issuer  =$_POST["x509_issuer"];
$x509_subject=$_POST["x509_subject"];  
$max_questions =$_POST["max_questions"];
$max_updates=$_POST["max_updates"];
$max_connections=$_POST["max_connection"];






// Set the preveleges for the mysql varables to insert to
database in this
//example the priveleges are set to 0 but make changes.

// To set the preveleges correctly goto your myphpadmin
//use database mysql and table user and check the prevles
are correct.


$Host="localhost";
$User=($User);
$password=(md5($password));  
$Select_priv="0";  
$Insert_priv="0";
$Update_priv="0";  
$Delete_priv="0";  
$Create_priv="0";
$Drop_priv="0";
$Reload_priv="0";  
$Shutdown_priv="0";
$Process_priv="0";  
$File_priv="0";
$Grant_priv="0";  
$References_priv="0";
$Index_priv="0";
$Alter_priv ="0";  
$Show_db_priv="0";
$Super_priv= "0";
$Create_tmp_table_priv ="0";
$Lock_tables_priv ="0";  
$Execute_priv="0";
$Repl_slave_priv ="0";
$Repl_client_priv="0";
$ssl_type ="0";  
$ssl_cipher ="0";
$x509_issuer  ="0";
$x509_subject="0";  
$max_questions ="0";
$max_updates="0";
$max_connections="0";


// If submit insert the data.

if($submit) {


INSERT INTO user VALUES('$Host','$User','$password',
'$Select_priv', '$Insert_priv','$Update_priv' ,'$Delete_priv',

'$Create_priv','$Drop_priv','$Reload_priv' ,'$Shutdown_priv',
'$Process_priv' , '$File_priv','$Grant_priv'

,'$References_priv','$Index_priv', '$Alter_priv' , '$Show_db_priv'
,'$Super_priv', '$Create_tmp_table_priv

','$Lock_tables_priv','$Execute_priv','$Repl_slave_priv', '$Repl_client_priv',
'$ssl_type' , '$ssl_cipher', '$x509_issuer'

,'$x509_subject' , '$max_questions' ,'$max_updates','$max_connections);

}





?>


//Get new name and Pssword for the mysql database.


<table border="1">
<td>
<form name="form" method="post" action"">
<input type="text" name="User">New mysql connection
username please:  (The same one as registered with)
<input type="password" name="password">New mysql connection
password please: (make a new password for your connection)
<input type="submit" name="submit">
</td>
</table>

// Script finished.



finally!

// When you set your mysql connection please use
your new connection name and password.


//$sql_host =   'localhost';  //Leave as defualt:
//$sql_un   =   'xxxxxxx';  //add your username here
//$sql_pass =   'xxxxxxx';  //add your password here
//$sql_db   =   'xxxxxxxx';  //add your database name here.


//mysql_connect("$sql_host", "$sql_un", "$sql_pass") or
    die ("Could not connect to database");
//mysql_select_db($sql_db) or
//    die ("Could not select database");
[/code]
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.