Create new database with UAPI functions.

Zubair Moolla

Registered
Feb 19, 2017
2
0
1
Auckland
cPanel Access Level
Root Administrator
Hi,

I am trying to create a MySQL database and set a current database user to the database.

The PHP code is written as below;

$site = "http://[cpanel_user]:[cpanel_password]@localhost:2082/execute/Mysql/";

$result = file_get_contents("{$site}create_database?name=zubair_test");
$result .= file_get_contents("{$site}set_privileges_on_database?user=zubair_admin&database=zubair_test&privileges=ALL%20PRIVILEGES");

print $result;

Now the database is being created fine with no errors, and it is mapped to the correct CPANEL user.

The issue I am having is setting a current database user to the newly created database. I am receiving the following error response.

{"errors":["(XID kamdnm) Database Error: There is no such grant defined for user 'zubair_admin' on host 'localhost'"],"status":0,"data":null,"messages":null,"metadata":{}}

Am I handling this the correct way to add a user to the newly created database? Perhaps could be a permissions issue with the current connection to MySQL? (The database user 'zubair_admin' I am trying to set to the database is the user I am connecting with).

Any advice or solutions will be much appreciated.

Thanks,
Zubair.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,903
2,237
463
Hello,

Could you verify which version of cPanel is installed on this system? EX:

Code:
cat /usr/local/cpanel/version
Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,903
2,237
463
{"errors":["(XID kamdnm) Database Error: There is no such grant defined for user 'zubair_admin' on host 'localhost'"],"status":0,"data":null,"messages":null,"metadata":{}}
Hello,

Could you verify how you are adding the database user? Can you reproduce the issue with newly created database users?

The following document is helpful if you have made direct changes to a MySQL user's grants in the past:

The dbstoregrants Script - Documentation - cPanel Documentation

Thank you.