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.

Create database on account creation

Discussion in 'cPanel Developers' started by atDev, Feb 3, 2012.

  1. atDev

    atDev Member

    Joined:
    Feb 15, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    We are using the tutorial here:
    Frequently Asked Scripts: "How do I automate XYZ after creating an account?" - cPanel Integration

    It seems like it creates the database and assigns the user but we get a few errors in the cpanel error log. Any ideas?

    [2012-02-03 09:22:45 -0600] info [cpmysqladmin] Creating MySQL database bbbtest__test for user bbbtest
    [2012-02-03 09:22:45 -0600] info [cpmysqladmin] Creating MySQL virtual user bbbtest__test for user bbbtest
    mysqladmin: User bbbtest does not own (bbbtest_)!
    [2012-02-03 09:22:46 -0600] warn [cpanel] Cpanel::AdminBin::adminrun(cpmysql) set error in context mysql
    [2012-02-03 09:22:46 -0600] warn [mysql::adduserdb] Encountered error in mysql::adduserdb: Error from cpmysql wrapper: You do not own the user (bbbtest_)!
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    What's the call you're using to create the database user?

    Does the user actually have the database permissions you set? It appears that mysqladmin is rejecting the addition.
     
  3. atDev

    atDev Member

    Joined:
    Feb 15, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    It ended up being my error. I didn't set the $permission flag properly in the example code.

    On another side question, is that tutorial using an older version of the API that will be deprecated soon? It seems like I saw a note that we should be using the "Live" version?
     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    LiveAPI is the preferred new method for calling API calls as it allows you to call them directly from code inside the cPanel interface. I doubt the XML/JSON APIs will be deprecated anytime in the near future. Here's the LiveAPI stuff:

    LiveAPI

    What you should take a look at is the new Standardized Hooks system. It provides more information about what's going on with your hooks and the ability to have multiple hooks per api call (insertion point). That way, if you install some script or plugin later that also needs to use postwwwacct, it won't override your existing /scripts/postwwwacct as you'll be using a standardized hook instead:

    Basic Usage | Standardized Hooks
     
  5. atDev

    atDev Member

    Joined:
    Feb 15, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Thanks that helps quite a bit. Do you happen to provide freelance services?

    I have the example version working for that blog and I want to go ahead and move it to the LiveAPI and then use the hooks.

    Will much of the code differ or just changing which class I extend and the parameters passed to the API calls? I assume API2 is better to call?
     
  6. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    I do work with companies to launch new products but typically don't work on a per project basis. More info at my site about some of the products I've helped launch.


    Depends on how object oriented your code is. It should be a pretty simple swap to swap out whatever function used to call cPanel to something like:

    Code:
    function cpanelAPI ( $version, $module, $function, $params ){
        $cpanel = new CPANEL();
    
        $response = $cpanel->api( 'exec', $version, $module,  $function, $params );
        
        //do some error checking
        //parse out response
    
        return $result;  
    
    }
    

    API2 typically has better error handling. An advantage as well is it has named input parameters so you can write code like:

    Code:
    array( 'user' => 'bob' )
    
    In API1, the arguments are not named, and are passed as a list.
     
Loading...

Share This Page