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?
2
Answers
I have the answer at last. Although I am not sure if it is the best answer. At the moment it is the only answer. If you can give me a better solution. I will of course tick yours instead. I am getting the id back with the preg match then stripping the id tag and using the id to create a user.
You can use any of PHP built-in XML parsers like SimpleXML or DOMDocument