Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2003
    Location
    Proud She-Geek
    Posts
    1,722

    Create mySQL DB for cPanel with PHP?

    Does anyone know of a script (or if it is even possible) to remotely create a database for cPanel by entering the standard information: IP, username, etc using a PHP script?
    <?php echo "Signature here"; ?>

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Sure its possible. You just need to login to the database with a user that has privileges to create databases.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  3. #3
    Join Date
    Jun 2003
    Location
    Proud She-Geek
    Posts
    1,722
    So, for example, if user joe had an account on a cpanel server he could enter his cpanel username/pass, along with the ip, desired database name (ie joe_database) and db user/pass (ie joe_username/password), and it should set be able to set it up?
    <?php echo "Signature here"; ?>

  4. #4
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Yes. You just need to execute the appropriate SQL commands against the server, and to do that, you need to login to the server as a user that has rights to create databases and assign permissions globally.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  5. #5
    Join Date
    Feb 2005
    Location
    Norway
    Posts
    391
    PHP Code:

    $host 
    "localhost";  // IP here if remotely..
    $port "2082"// cPanel port
    $user "username";  // cPanel username..
    $pass "password";  // cPanel password..
    $dbtoadd "something"// database name to b added..
    $cpmod "x";  // cPanel skin.. ex; bluelagoon.. rvskin.. x.. etc..



    function sqldb($host,$port,$user,$pass,$request)  {
    global 
    $dbtoadd,$password;

    $request "/frontend/$cpmod/sql/adddb.html?db=$dbtoadd";

    $result sqldb($host,$port,$user,$pass,$request); 
    This will make a MySql database in cPanel..
    Last edited by UrlGuy; 06-20-2005 at 09:47 AM.

  6. #6
    Join Date
    Feb 2005
    Location
    Norway
    Posts
    391
    Adding a MySql user..

    $usertoadd = "user"; // db user
    $cpmod = "x"; // cPanel skin
    $passfordb = "secret"; // db pass

    $request="http://$user:$pass@$host:$port/frontend/$cpmod/sql/adduser.html?user=$usertoadd&pass=$passfordb";

  7. #7
    Join Date
    Feb 2005
    Location
    Norway
    Posts
    391
    Attaching the MySql user to the database...


    $underscore ="_";
    $dbtobeaddedto = "something"; // which db to add it to..
    $usertoadd = "someuser"; // db user to add (must be made in advance)

    $request = "/frontend/$cpmod/sql/addusertodb.html?user=$user$underscore$dbtobaddedto&db=$usertoadd$underscore$dbtobeadded&ALL=ALL";

    ALL=ALL is permissions..


    (^_^ beware of typos in my posts :\)
    I am very newb to PHP myself and all knowledge I got about it is gethered from PHP experts here and thruout tutorials all over the web.. so .. most likely the above stuff could have been done in a way easier way.. - but its my way.. and it workd well for me as a beginner :]

    If you'r after more functions you can automate in cPanel just run the functions you want using for example Internet Explorer which is hooked up with a packet sniffer..


    To make the whole thing alot easier you could just make a HTML form.. fill in variables in some config file.. so the user would only need to type in db, db user to be added and such.. and if not in config file.. - their cPanel login.. and maybe include all of the stuff which are in my 2 above posts into 1 file so you asked him to enter a user+pass and it would make a db and a db user with that username.. and its pass

    Also you can check: http://www.cpanel.net/remoteaccess-php.html
    Last edited by UrlGuy; 06-20-2005 at 09:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •