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 new db via php mysql script in app

Discussion in 'cPanel Developers' started by jeffpo, Jan 17, 2015.

  1. jeffpo

    jeffpo Registered

    Joined:
    Jan 17, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I am totally lost on how to tie this in with my app.During registration my app automatically creates a new db per user and I have it working locally via mamp with my php sql script but I need to change the sql code to do this via cpanel. Ive tried to use this code via github but just get a blank page

    Code:
    require("xmlapi.php"); // this can be downlaoded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php
    $xmlapi = new xmlapi("your cpanel domain");   
    $xmlapi->set_port( 2083 );   
    $xmlapi->password_auth($opts['user'],$opts['pass']);    
    $xmlapi->set_debug(0);//output actions in the error log 1 for true and 0 false 
    
    $cpaneluser=$opts['user'];
    $databasename="something";
    $databaseuser="else";
    $databasepass=$opts['pass'];
    
    //create database    
    $createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename));   
    //create user 
    $usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));   
    //add user 
    $addusr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduserdb", array("".$cpaneluser."_".$databasename."", "".$cpaneluser."_".$databaseuser."", 'all'));
    
    But I think the areas that need to be edited are not clear to me, can someone give me a dummy guide through this . Thank you in advance
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page