API 2 how to create new database and set existing user Privilege
We are trying to create database through api 2. but we can't acheieve it. How do we require the class Cpanel .
Here is our tried code. but didnt work.
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
$database = 'exampl_db';
$create_database = $cpanel->api2(
'MysqlFE', 'createdb',
array(
'db' => $database,
)
);
if($create_database == 1) {
$grant_user = $cpanel->api2(
'MysqlFE', 'setdbuserprivileges',
array(
'privileges' => 'ALL PRIVILEGES',
'db' => $database,
'dbuser' => 'username',
)
);
and we got this error " Fatal error: Uncaught Error: Class 'CPANEL' not found in" So we tried to require the cpanel program.
require_once "/usr/local/cpanel/php/cpanel.php"; on the same file
-
Why not use the UAPI to do this? Guide to the LiveAPI System - Developer Documentation - cPanel Documentation 0 -
thank you this is great idea to use UAPI, i have got it working after chaning it to UAPI. 0 -
That's great news! I'm happy to hear that. Any time there is a UAPI function for something I'd recommend using it over the cpapi2 0
Please sign in to leave a comment.
Comments
3 comments