Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

[whm plugin] create database for user

Discussion in 'cPanel Developers' started by kris.x15, Nov 11, 2010.

  1. kris.x15

    kris.x15 Member

    Joined:
    Sep 20, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    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.
     
  2. MattDees

    MattDees Well-Known Member

    Joined:
    Apr 29, 2005
    Messages:
    416
    Likes Received:
    1
    Trophy Points:
    243
    Location:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice