A PHP Class for Interacting with cPanel’s XML-API

https://github.com/CpanelInc/xmlapi-php

<?php

include(“xmlapi.php”);
$db_host = “localhost”;
$cpaneluser = “cpaneluser”;
$databasename = ‘mydatabasename’;//do not prepend with username
$databaseuser = ‘databaseuser’;//api will do that for you
$cpanelpass = ‘cpanelpass’;
$databasepass = ‘cpanelpass’;

$xmlapi = new xmlapi($db_host);
$xmlapi->password_auth(“”.$cpaneluser.””,””.$cpanelpass.””);
$xmlapi->set_debug(1);//output actions in the error log 1 for true and 0 false
$xmlapi->set_output(‘array’);//set this for browser output
//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’));

?>

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *