Api cant add database to existing user

St33fman

New member
Joined
May 21, 2010
Messages
1
Hello all,

After viewing 3 day`s in a row, al the forum post on this topic and
also googled to the end of the internet hahaha
I didn`t find the sollution, and hope somebody here can help me.

I got a system that uses 1 db username and password for a lot of databases,
now when i want to create a new database for this user, the api says

Error creating the database, user already exist.

the code i use is
//////

$sock->query('/CMD_API_DATABASES',
array(
'action' => 'create',
'domain' => 'mydomain.com',
'name' => $_POST['dbname'],
'user' => 'MyUsername',
'passwd' => 'mypassword',
'passwd2' => 'mypassword,
'create' => 'Create'
));

///////

now my question...
Is there a way to add a database to the existing user?

Best Regards
Stefan
 
I am having the same problem. I can create a database for a user that has been in the system for a while, but when I try to create a user then turn right around and create a database for that user that I just added, I get the same error.


function createUserAccount($user,$pass,$email,$domain)
{
$sock = new HTTPSocket;
$sock->connect('mydomain.com',2222);
$sock->set_login("reseller","resellerpassword");
$sock->set_method('POST');
$sock->query('/CMD_API_ACCOUNT_USER',
array(
'action' => 'create',
'add' => 'Submit',
'username' => $user,
'passwd' => $pass,
'passwd2' => $pass,
'email' => $email,
'domain' => $domain,
'package' => 'Package',
'ip' => '123.123.123.123',
'notify' => 'no'
));
$data = $sock->fetch_body();

$data = explode("&",$data);
foreach($data as $temp) {
$temp = explode("=",$temp);
$results[$temp[0]] = @$temp[1];
}

return $results;
}

function createUserDatabase($user,$pass)
{
$sock = new HTTPSocket;
$sock->connect('mydomain.com',2222);
$sock->set_login($user,$pass);
$sock->set_method('POST');
$array = array();
$array['action'] = 'create';
$array['name'] = 'main';
$array['user'] = $user;
$array['passwd'] = $pass;
$array['passwd2'] = $pass;
$sock->query('/CMD_API_DATABASES',$array);
$data = $sock->fetch_body();

$data = explode("&",$data);
foreach($data as $temp) {
$temp = explode("=",$temp);
$results[$temp[0]] = @$temp[1];
}

return $results;
}

$result = createUserAccount('testing','test123456','[email protected]','testdomain.com');
print_r($result);
echo "<br><br>";
$result = createUserDatabase('testing','test123456');
print_r($result);


Here is the testing script that I use (with values changed). The user gets created under the reseller properly, but when I try to log in as the user that was just created, I get the same error.....

Array ( [error] => 0 [text] => User testing created [details] => [#60br] => [#62 Unix User created successfully] => [#62 ] => [#62 User] => [#39s System Quotas set] => [#39s data directory created successfully] => [#62 Domains directory created successfully] => [#62 Domains directory created successfully in user] => [#39s home] => [#62 Domain Created Successfully] => [#60b] => [#62Script output] => [#60/b] => [#62] => [#58 /usr/local/directadmin/scripts/custom/user] => [#95create] => [#95post.sh] => )

Array ( [error] => 1 [text] => Error creating the database [details] => [#60br] => [#62 That user already Exists] => [#62 ] => )

I REALLY need this to work so if anyone has any ideas of how I can get this to work, I would really appreciate the information.
 
I think I figured it out. Through testing, I had ran the script before of course and the user testing_testing DID already exist under the privelages tab in phpMyAdmin. So if anyone is having problems with this, check your privelages table for existing users.
 
The Problem is the API always want to create a new user... How to get arround? I'm totally stuck. Our system relies on the same database user.. so this is a must have for our system.

Any solutions yet?
 
Does the database user already exist? You should be able to just select any existing database user.
 
Does the database user already exist? You should be able to just select any existing database user.

In directadmin self, yes. But in the API it's not working?

My query:

PHP:
$sock->query('/CMD_API_DATABASES',
        array(
                'action' => 'create',
                'name' => "databasename",
                'user' => "existingusername",
                'passwd' => "Passwordhere",
                'passwd2' => "Passwordhere",

    ));

Any solutions? Still stuck..

PHP:
 
Back
Top