Ho w to lunch and write a php scritp for mysql query

Hello to all,

have informed me that we need to expand our service desk and in the new project would build a new feature of the current IVR .

In , in a certain point of the new IVR will have to be able to enter the number of your ticket, then asterisk dio query a db and the query that will do will give a result , this resul will have to return to my dialplan and at that point , depending on the outcome , it will run a specific audio file .

I arrived at this point in my tests :

exten = > _01875295401 , 1 , Answer ()
exten = > _01875295401 , n, Read ( input , ticket2 , )
exten = > _01875295401 , n, SayDigits ($ {input })
exten = > _01875295401 , n, DeadAGI ( database.php , $ {input })

"here obviously missing the whole part concerning the processing of the query result "

exten = > _01875295401 , n, Hangup ( ) and ,

It ’ a test, however, the diaplan takes me correctly the variable input and repeats , then launches the script and passes the variable input.

The script is trivial at the time , and does not ninete if not a db connetc .

My question is , how do I create the PHP? I’m very noob on this language

The query that I have to do is the following:

select a.name from ticket_state in , ticket b.tn where b = [ here will be the value of the variable populated by asterisk ] and a.id = b.ticket_state_id ;

the result can be only 4 types , id1 , id2 , id3 , ID4

Thanks in advance

I’v ewite this script but not work

#!/usr/bin/php -q

<?php require('/var/lib/asterisk/agi-bin/phpagi.php'); $agi = new AGI(); $agi->answer(); $input=$argv[1]; $data=$argv[2]; // Connects to your Database mysql_connect("10.7.34.89", "davide", "1234") or die(mysql_error()); mysql_select_db("otrs") or die(mysql_error()); $data = mysql_query("SELECT a.name FROM ticket_state a, ticket b WHERE b.tn = 2014021310000016 and a.id = b.ticket_state_id;") or die(mysql_error()); $agi -> get_variable('id','$data'); mysql_close() If i lunch from commandline give me this answer ANSWER GET VARIABLE id Any ideas?

Hi asyscom!

The last post here is the way I do it in the dialplan:
http://forums.digium.com/viewtopic.php?f=1&t=80240&sid=8f51cbc6285e16fedd74d71775bfb913

It might be useful for you.

Virtually yours // Nypon

Is there some reason why not just use common asterisk modules to just do this in the dialplan directly? For examples, you could add func_odbc.so to your modules.conf. Now, simply specify a dsn (I think in asterisk.conf, maybe somewhere else, though). Now just populate readsql/writesql queries to func_odbc and use them directly in the dialplan.