Archive for October, 2008

Creating databases in cpanel remotely

Lately I was wondering how one would go about creating databases in cpanel without having to log on. Do it from PHP or something and create a somewhat ‘nicer’ interface to that ‘nice’ cpanel stuff.

It proved to be trivial to do anything with the system; that is in face kind of nice and has been a relief for me as I thought it would be (much) more difficult.

Here is a code snippet how to do this easily. It return PHPartialsResult, but you can replace that with ‘true’ or something.


function remote_account_create_db($host, $user, $pass, $dbname) {
$conn = "http://$user:$pass@$host:2082/frontend/x3/sql/addb.html?db=$dbname";
file_get_contents($conn);
return PHPartialsResult::ok();
}

function remote_account_create_dbuser($host, $user, $pass, $_user, $_pass) {
$conn = "http://$user:$pass@$host:2082/frontend/x3/sql/adduser.html?user=$_user&pass=$pass&pass2=$pass";
file_get_contents($conn);
return PHPartialsResult::ok();
}

function remote_account_create_dbuserconnection($host, $user, $pass, $_user, $_db) {
$conn = "http://$user:$pass@$host:2082/frontend/x3/sql/addusertodb.html?ALL=ALL&user=$_user&db=$_db";
file_get_contents($conn);
return PHPartialsResult::ok();
}