gpt4 book ai didi

php - 通过php脚本创建cpanel数据库

转载 作者:可可西里 更新时间:2023-10-31 23:54:56 26 4
gpt4 key购买 nike

我正在尝试使用 cpanel/whm 和 postwwwacct php 脚本自动安装一些自定义软件。这需要将文件复制到用户 public_html 文件夹,然后编辑配置并设置 eh 文件权限。到目前为止一切顺利,没有问题。在尝试创建数据库时遇到了一些问题。

    $db_create= $opts['user']. '_lol';  
$db_host="immersion-networks.com";
include("xmlapi.php");
$xmlapi = new xmlapi($db_host);
$xmlapi->password_auth("".$opts['user']."","".$opts['pass']."");
$xmlapi->set_debug(1);//output actions in the error log 1 for true and 0 false
$xmlapi->set_output('array');//set this for browser output
//create database
$createdb = $xmlapi->api1_query($opts['user'], "Mysql", "adddb", array($db_create));
//create user
$usr = $xmlapi->api1_query($opts['user'], "Mysql", "adduser", array($db_create, $opts['pass']));
//add user
$addusr = $xmlapi->api1_query($opts['user'], "Mysql", "adduserdb", array($db_create,$db_create, 'all'));

其余代码运行正常,但没有创建数据库,也没有创建用户。有什么想法吗?

最佳答案

require("xmlapi.php"); // this can be downlaoded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php
$xmlapi = new xmlapi("your cpanel domain");
$xmlapi->set_port( 2083 );
$xmlapi->password_auth($opts['user'],$opts['pass']);
$xmlapi->set_debug(0);//output actions in the error log 1 for true and 0 false

$cpaneluser=$opts['user'];
$databasename="something";
$databaseuser="else";
$databasepass=$opts['pass'];

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

上面的代码对我有用!需要确保您使用的是 cpanel 用户/密码而不是 root,并且您使用的是端口 2083

关于php - 通过php脚本创建cpanel数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11989920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com