Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    6

    Default [whm plugin] create database for user

    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. #2
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default Re: [whm plugin] create database for user

    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 Code:
    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.
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

Similar Threads & Tags
Similar threads

  1. Replies: 2
    Last Post: 10-24-2011, 02:13 PM
  2. Replies: 1
    Last Post: 02-11-2011, 04:55 PM
  3. Automatically create mysql user and database for new WHM accounts?
    By joachim.n in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 06-19-2009, 11:14 AM
  4. mySQL user which can create new database
    By awa in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 07-23-2008, 04:58 AM
  5. Can't create user to add them to a database
    By dsecrets in forum Database Discussions
    Replies: 4
    Last Post: 01-02-2008, 08:36 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube