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 with php/curl

Discussion in 'General Discussion' started by kgp, Nov 8, 2008.

  1. kgp

    kgp Registered

    Joined:
    Nov 8, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I have been using the last 2 days trying to figure out how to make a database (programming), but nothing seems to work and it's about to drive me insane.

    Hope someone can help me.

    Examples what i have been trying:

    http://$username:$password@$website:2082/frontend/x/sql/adddb.html?db=$db_name

    shell_exec("$curl_path http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/addb.html?db=$db>> /dev/null");


    Any suggestions?
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Do you have reseller or root access to the server, or only a single hosting account on the server? I ask because if you have reseller access or higher, you can use our APIs.
     
  3. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Its my own server, got root access.
    Possible to point to in the right direction?
     
    #3 kgp43, Nov 10, 2008
    Last edited: Nov 10, 2008
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Sure, to create a database using our APIs, it's an API1 call as used in:

    /usr/local/cpanel/base/frontend/x3/sql/addb.html (there's only 2 d's)

    The actual function call in that source is:

    Code:
    <cpanel Mysql="adddb($FORM{'db'})">
    Meaning, to create a database named example in raw API1 code, you would use:

    Code:
    <cpanel Mysql="adddb(example)">
    Note, the username_ prefix will be automatically added, so try to keep your database names to 7 characters or less.

    Now, to call this from outside the cPanel interface, we'll use the XML API. A sample for calling API1 functions with arguments can be found at:

    http://www.cpanel.net/plugins/xmlapi/cpanel.html

    The URL to call to create a database named "example" for a user with username "cPanelUser" would be:

    https://server:2087/xml-api/cpanel?user=cPanelUser&xmlin=<cpanelaction><module>Mysql</module><func>adddb</func><apiversion>1</apiversion><args>example</args></cpanelaction>

    There are code samples around these forums for helping with the XML-API and API1/API2. If you desire swifter responses from me, please send an email to sales@cpanel.net with ATTN: DavidG in the subject line.
     
  5. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Thanks alot :)
     
  6. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Hi David,

    I managed to create the database, using the link you provided.
    But i need to type the root password, i can probably integrated it into the link, but i dont find that secure.

    Any suggestions?
     
  7. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    I tried somethign different this time, someone told me this will work.
    But no database show up in WHM.


    function cpanel($user,$pass,$domain,$theme="x",$port="2082") {
    $this->set_username = $user;
    $this->set_password = $pass;
    $this->set_domain = $domain;
    $this->set_theme = $theme;
    $this->set_port = $port;
    }

    function CreateDB($db) {
    @file("http://".$this->set_username.":".$this->set_password."@".$this->set_domain.":".$this->set_port."/frontend/".$this->set_theme.
    "/sql/adddb.html?db=".$db);
    }


    $cuser = "username";
    $cpass = "password";
    $cdomain = "123.456.456.23"; // I use IP instead of domain

    $cpanel = new cpanel($cuser,$cpass,$cdomain);
    $cpanel->CreateDB("newdb");
     
Loading...

Share This Page