WHM Database Creation / Config

lewisstevens1

Member
Oct 18, 2013
9
0
1
cPanel Access Level
Root Administrator
Hello i was just wondering if there's any PHP way of CREATING A DATABASE, CREATE A NEW MYSQL USER (Username & Password), ASSIGN THE USER TO THE DATABASE?

I know how to create tables, but i would like to add the databases automatically via a script so that i dont have to go in and configure a database everytime a new account is created.

The attached image shows what process i would like automated via PHP.

Many thanks
Lewis:D

database.jpg
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello :)

You could utilize our API for database functions. This is documented at:

cPanel - Software Development Kit

You can also search our forums for a term such as "API create database" and find several results.

Thank you.
 

lewisstevens1

Member
Oct 18, 2013
9
0
1
cPanel Access Level
Root Administrator
Hi, problem is, i cannot find any references on creating the database, i use:
$query = "https://".$ip_address2.":2087/json-api/createacct";
$query .= "?username=".$new_user4;
$query .= "&password=".$new_password;
$query .= "&domain=".$new_user2.$domain_ext;
$query .= "&[email protected]";
$query .= "&plan=".$server_package2;
$query .= "&cgi=0";

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_HEADER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if ($result == false) {
echo "0"; // Installation Failed
} else {
echo "1"; // Installed
//include_once('../setup_files/installation_query.php');
}
curl_close($curl);
This generates the account ect. but doesnt create the database.. and i cannot find any documentation on creating a database, even here.. XML and JSON APIs
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463