IVR GUI tool to generate AGI script

I am reading a lot of AGI related document, including phpagi, and getting a little confused. I really need some help before starting coding. My task is to automatically generate Asterisk AGI script for any IVR application designed in our IVR GUI tool (Voicent IVR Studio). Currently, the tool will generate VoiceXML script, which is a much higher level language than AGI script.

The basic voice interactions, such as play an audio file and wait for DTMF tone input, are pretty straightforward. However, in Voicent IVR or VoiceXML, we have commands to connect to a database and perform SQL statements, or link to a SMTP server. So how can I implement these features using Asterisk AGI?

I’d appreciate if anyone can also share his experience automatically generating AGI based IVR applications.

¬¬

Not sure if trolling/advertising or making a real Question.

Do you have a question about what my question is? It could be confusing if you are not familiar with AGI interface. Without the background info, the question basically is: how to perform a database query in a generated AGI script and use the query result in later steps of the IVR script.

Hope this clarifies the confusion.

To connect to any Database Engine from the AGI script use the libraries/methods supplied by your preferred program language, i.e. I use PHP for make the AGI then I use the mysql/postgres extension to connect to the database engine.

To return a value I only use the Set_Variable command supplied by the phpagi library.

I expect from a developer to have the knowledge on how to connect to an DB engine, since google have a lot-a lot- information about that.