Search code examples
phpxmldatabaseapiplesk

In plesk api how do I add a user to a database if I don't know the database id


With help from Oleg Neumyvakin I have managed to use plesk api to create a database, but now I need to add a user to that database. I have worked out how to add a user to a database,but it requires knowing the id of the database, which I won't know in php. For instance the following request code creates the database

<packet>
<database>
<add-db>
   <webspace-id>$webspaceId</webspace-id>
   <name>$dbName</name>
   <type>mysql</type>
</add-db>
</database>
</packet>

And the following code creates a user and adds it to the database

<packet>
<database>
  <add-db-user>
      <db-id>26</db-id>
      <login>zebra</login>
      <password>zebra500</password>
   </add-db-user>
</database>
</packet>

You can see my problem. The second part uses the id of the database which is 26 to add the user, but I don't know the id without looking in plesk, and that defeats the object.

So how do I create the database and add the user at the same time?


Solution

  • You can use any of PHP built-in XML parsers like SimpleXML or DOMDocument