1

I created new cPanel account, using this account created new database, new database user and connected user to database, simple stuff. Now, I want this particular user to be able to create new databases, how can I escalate this database user's permissions to allow creating new databases? I still want these databases to be associated with cPanel account, is adding account name prefix (account_) to database name enough to associate it with that cPanel account?

Edit: Whoops, forgot to mention - database is MySQL.

2 Answers 2

2

You sould read the online manual that contains all the proper procedures, but where's how you can do it:

<?php

include("xmlapi.php");  
$db_host = "localhost";  
$cpuser = "myuser";  
$databasename = 'mydatabasename';//do not prepend with username
$databaseuser = 'mydatabaseuser';//api will do that for you
$databasepass = '123456';

$xmlapi = new xmlapi($db_host);  
$xmlapi->password_auth("root","root_pass");  
$xmlapi->set_debug(1);//this setting will put output into the error log in the directory that you are calling script from 
$xmlapi->set_output('array');//set this for browser output

//create database  
$createdb = $xmlapi->api1_query($cpuser, "Mysql", "adddb", array($databasename)); 
foreach($createdb as $v)
{
    $result = $v['result'];
}
if ($result == 1)
{
    //create user  
    $usr = $xmlapi->api1_query($cpuser, "Mysql", "adduser", array($databaseuser, $databasepass));  
}
foreach($usr as $v)
{
    $result2 = $v['result'];
}
if ($result2 == 1)
{
    //add user to database  
    $addusr = $xmlapi->api1_query($cpuser, "Mysql", "adduserdb", array($databasename, $databaseuser, 'all'));  

}
print_r($addusr);


?>

This should be adapted to your API, but what it does is allow the DB creation, with a user creation, and finally, associate then!

Ps: see xmlapi-php-class

Hope it helps you...

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Zuul, last time I was working with cPanel/WHM API it didn't have database calls, so this is great news.
0

If i understand correctly your question, you want to grant access to certain user to be able to create new databases in this particular user account. correct?

If so, when you create a new domain/user in CPANEL/WHM, you can define how many databases the user will have. So, if you define to this user, for example, 3 databases, you will grant to this user that he can create 3 databases.

That's all...if i understand correctly your question.

Regards

1 Comment

Nope, that's not it. cPanel user has unlimited number of databases, what I want to do is allow database user to create new databases. I need this so I can create new databases on the fly, without having to login to cPanel and create them manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.