Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

create database without login to cpanel

Discussion in 'cPanel Developers' started by Rohan Purekar, May 31, 2015.

  1. Rohan Purekar

    Rohan Purekar Registered

    Joined:
    May 31, 2015
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Nagpur
    cPanel Access Level:
    Website Owner
    Warning: Illegal string offset 'result'
    Warning: Invalid argument supplied for foreach() i am getting the following errors

    here's the code of tomdchi which i used
    Code:
    include("xmlapi.php"); 
    $db_host = "mydomain.com"; 
    $cpuser = "cpusername"; 
    $databasename = 'wxa';//do not prepend with username
    $databaseuser = 'mynewuser';//api will do that for you
    $databasepass = 'pass';
    
    $xmlapi = new xmlapi($db_host); 
    $xmlapi->password_auth("cpanelusername","cpanelpassword"); 
    $xmlapi->set_debug(1);//this setting will put output into the error log in the directory that you are calling script from
    $xmlapi->set_output('array');//set this for browser output
    //create database 
    $createdb = $xmlapi->api1_query($cpuser, "Mysql", "adddb", array($databasename));
    foreach($createdb as $v)
    {
        $result = $v['result'];
    }
    if ($result == 1)
    {
        //create user 
        $usr = $xmlapi->api1_query($cpuser, "Mysql", "adduser", array($databaseuser, $databasepass)); 
    }
    foreach($usr as $v)
    {
        $result2 = $v['result'];
    }
    if ($result2 == 1)
    {
        //add user to database 
        $addusr = $xmlapi->api1_query($cpuser, "Mysql", "adduserdb", array($databasename, $databaseuser, 'all')); 
    
    }
    print_r($addusr);
    
    
     
    #1 Rohan Purekar, May 31, 2015
    Last edited by a moderator: May 31, 2015
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,323
    Likes Received:
    1,851
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    I moved this post into it's own thread, as the example and thread you are using is over five years old. I suggest using cPanel API 2. Documentation on this module is available at:

    cPanel API 2 Functions - MysqlFE::createdb

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. tecwithquestion

    tecwithquestion Well-Known Member

    Joined:
    Oct 20, 2014
    Messages:
    57
    Likes Received:
    1
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Try this one
    <?php
    include("xmlapi.php");
    $db_host = "localhost";
    $cpuser = "user";
    $databasename = 'dbb';//do not prepend with username
    $databaseuser = 'dbb';//api will do that for you
    $databasepass = 'P3cJdlvx/vAo5cSRR5djAA==';

    $xmlapi = new xmlapi($db_host);
    $xmlapi->password_auth("root","rootpass");
    $xmlapi->set_debug(1);//this setting will put output into the error log in the directory that you are calling script from
    $xmlapi->set_output('array');//set this for browser output
    //create database
    $createdb = $xmlapi->api1_query($cpuser, "Mysql", "adddb", array($databasename));
    foreach($createdb as $v)
    {
    $result = $v['result'];
    }
    if ($result == 1)
    {
    //create user
    $usr = $xmlapi->api1_query($cpuser, "Mysql", "adduser", array($databaseuser, $databasepass));
    }
    foreach($usr as $v)
    {
    $result2 = $v['result'];
    }
    if ($result2 == 1)
    {
    //add user to database
    $addusr = $xmlapi->api1_query($cpuser, "Mysql", "adduserdb", array($databasename, $databaseuser, 'all'));

    }
    print_r($addusr);


    ?>
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice