The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[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:
    6
    Likes Received:
    0
    Trophy Points:
    1
    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 cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    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.
     

Share This Page