如何通过cpanel/whm API创建数据库? [英] How does one go about creating a database through the cpanel/whm API?

查看:191
本文介绍了如何通过cpanel/whm API创建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让API可以在专用服务器上为用户创建一个帐户,也可以创建电子邮件地址,但是,当我尝试通过API创建mysql数据库时,即使出现错误消息访问被拒绝",即使访问权限是根.

I have the API creating an account on a dedicated server for a user fine, creating email addresses fine as well, however when I attempt to create an mysql database through the API, I get error message 'Access Denied', even though access is root.

我要使用的代码:

$xmlapi = new xmlapi($host);
$xmlapi->password_auth("".$root_user."","".$root_pass."");    
$xmlapi->set_debug(1);
$xmlapi->set_output('array');
$xmlapi->set_port('2083'); 
//create database
$createdb = $xmlapi->api1_query($root_user, "Mysql", "adddb", array($dbname));

以及我返回的错误数据:

and the error data I am getting back:

URL: https://delta1.powerstorm.net:2083/xml-api/cpanel
DATA: cpanel_xmlapi_user=root&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adddb&cpanel_xmlapi_apiversion=1&arg-0=site
Authentication Header: Authorization: Basic cm9vdDphY3Jtp3MxOTY1

RESPONSE:
 <?xml version="1.0" ?>
<cpanelresult>
    <error>Access denied</error>
    <data>
        <result>0</result>
        <reason>Access denied</reason>
    </data>
</cpanelresult>

关于其他任何方面都工作正常的情况,为什么这一部分会失败的任何想法吗?

Any ideas on why this one part is failing when everything else works fine?

推荐答案

您不能使用root帐户创建cPanel数据库.另外,请确保设置端口. 2082用于未加密的连接,而2083用于加密.您也可以使用IP地址代替域名".

You can not use root account to create cPanel databases. Also, make sure to set the port. 2082 is for unencrypted connection, while 2083 is for encrypted. You can also use the IP address in place of "domainName".

检查下面的代码,使其正常工作.

Check the following code as it should work.

require("xmlapi.php");

$opts = [
    "userName"   => "UserUserName",      //+++ Replace UserUserName
    "password"   => "UserPassword",      //+++ Replace UserPassword
    "dbPassword" => "DatabasePassword",  //+++ Replace DatabasePassword
];

$xmlapi = new xmlapi("domainName");   
$xmlapi->set_port( 2083 );   
$xmlapi->password_auth($opts['userName'],$opts['password']);     

$cpaneluser=$opts['userName'];
$databasename="dbName";
$databaseuser="dbUserName";
$databasepass=$opts['dbPassword'];

// database creation    
$createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename));   
// user creation
$usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));   
// adds user to database
$addusr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduserdb", array("".$cpaneluser."_".$databasename."", "".$cpaneluser."_".$databaseuser."", 'all'));

这篇关于如何通过cpanel/whm API创建数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆