Hello,
I am using the cPanel API to automatically create a database, create a database user and then finally add that user with all permissions to that database.
This script has been working correctly for weeks and I have created around 100 databases with users.
Today I decided to clean up the databases that I had automatically created and deleted them through the Cpanel control panel.
Here is my PHP script
<?php
$domainAddress = 'mydomain';
$databaseuser = 'myuser';
$databasepass = 'mypass';
//create CPANEL database
include("xmlapi.php");
$db_host = "localhost";
$cpuser = "ACCOUNT_USER";
$databasename = $domainAddress;//do not prepend with username
//$databaseuser = random_string('alnum', 5);//api will do that for you
//$databasepass = random_string('alnum', 16);
$xmlapi = new xmlapi($db_host);
$xmlapi->password_auth("MAIN_ACCOUNT_USER","MAIN_ACCOUNT_PASS");
$xmlapi->set_debug(1);//this setting will put output into the error log in the directory that you are calling script from
$xmlapi->set_output('array');//set this for browser output
//create database
$createdb = $xmlapi->api1_query($cpuser, "Mysql", "adddb", array($databasename));
foreach($createdb as $v)
{
$result = $v['result'];
}
if ($result == 1)
{
//create user
$usr = $xmlapi->api1_query($cpuser, "Mysql", "adduser", array($databaseuser, $databasepass));
}
foreach($usr as $v)
{
$result2 = $v['result'];
}
if ($result2 == 1)
{
//add user to database
$addusr = $xmlapi->api1_query($cpuser, "Mysql", "adduserdb", array($databasename, $databaseuser, 'all'));
}
?>
This successfully creates a database called ACCOUNT_mydomain. It also successfully creates a user called ACCOUNT_myuser. HOWEVER IT FAILS when adding the user to the database.
The debug file says this:
[29-Dec-2010 01:32:11] RESPONSE:
<?xml version="1.0" ?>
<cpanelresult><module>Mysql</module><func>adduserdb</func><type>event</type><source>internal</source><apiversion>1</apiversion><data><result>You do not have access to that database (mydomain)!
</result></data> <event>
<result>1</result>
</event>
</cpanelresult>
[29-Dec-2010 01:32:11] SimpleXML var_dump:
SimpleXMLElement Object
(
[module] => Mysql
[func] => adduserdb
[type] => event
[source] => internal
[apiversion] => 1
[data] => SimpleXMLElement Object
(
[result] => You do not have access to that database (mydomain)!
)
[event] => SimpleXMLElement Object
(
[result] => 1
)
)
[29-Dec-2010 01:32:11] Associative Array var_dump:
Array
(
[module] => Mysql
[func] => adduserdb
[type] => event
[source] => internal
[apiversion] => 1
[data] => Array
(
[result] => You do not have access to that database (mydomain)!
)
[event] => Array
(
[result] => 1
)
)
I have already been through this issue with a chat technician who troubleshooted my script and has confirmed it should be working correctly.
As I have mentioned this script was working flawlessly for over a month.
My personal feeling is that deleting the databases and the users without deleted the links between the users and their databases has got the CPANEL API tied up in a Knot.
I also read that mysql will reject long user names and I did try shortening them down as low as I could but no difference. Once again... it was working only 5 hours ago.
Does anyone have any suggestions?
Thanks



LinkBack URL
About LinkBacks
In the meantime, you'd have to do your own manual error checking against MySQL to verify that the MySQL resource was created...which depending on your implementation may prove to be cumbersome 







