[whm plugin] create database for user

kris.x15

Member
Sep 20, 2010
8
0
51
Hi,

Is there a way to create database+user for cPanel existing user from whm/being logged as root?
I'm creating whm plugin using mostly PHP and I'm stuck on this one.
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
This can be done using the API1 call Mysql::adddb

when authenticated as root or a reseller that owns this account, you can call this via the cpanel xml-api api1/api2 wrapper, like thus:

Code:
/xml-api/cpanel?cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adddb&cpanel_xmlapi_apiversion=1&arg-0=__DATABASE_NAME_GOES_HERE__&cpanel_xmlapi_user=__USERNAME_GOES_HERE__
Now, we do provide an xml-api php client that allows you to work with this in a much simpler manner:

PHP:
include("xmlapi.php");

$ip = "127.0.0.1";
$root_pass = "testing";

$account = "cptest";
$database = "dbname";

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);

$xmlapi->set_debug(1);
print $xmlapi->api1_query($account, "Mysql", "adddb", array($database) );
Now, with this setup, you'll have to pull your $root_pass from REMOTE_PASS in the CGI environment and change the user querying the xml-api, but this will work.

Another alternative is to use the first example I showed you via javascript.