Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    kgp
    kgp is offline
    Registered User
    Join Date
    Nov 2008
    Posts
    1

    Default Create database with php/curl

    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. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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. #3
    Member
    Join Date
    Aug 2004
    Posts
    30

    Default

    Its my own server, got root access.
    Possible to point to in the right direction?
    Last edited by kgp43; 11-10-2008 at 12:34 PM.

  4. #4
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by kgp43 View Post
    Its my own server, got root access.
    Possible to point to in the right direction?
    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. #5
    Member
    Join Date
    Aug 2004
    Posts
    30

    Default

    Thanks alot

  6. #6
    Member
    Join Date
    Aug 2004
    Posts
    30

    Default

    Quote Originally Posted by cPanelDavidG View Post
    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.
    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. #7
    Member
    Join Date
    Aug 2004
    Posts
    30

    Default

    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");

Similar Threads & Tags
Similar threads

  1. PHP compiled with curl, but cannot find curl.so
    By racerx8413 in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 07-15-2011, 06:08 PM
  2. create database programaticly with php
    By tonyk in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 07-23-2008, 08:10 AM
  3. Rebuilt apache with PHP CURL but now PHP pages don't load.
    By turfsk8r in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 06-02-2007, 06:19 AM
  4. Replies: 0
    Last Post: 05-29-2006, 12:31 PM
  5. Create a database with PHP
    By erobs in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 10-09-2003, 12:25 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube