views:

34

answers:

2

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.

A: 

hi there,

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

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.
steelaz
+1  A: 

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...

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