AGI Programming - Return multiple variables to Dial plan

I created a very simple AGI script which retrieves information from a MS SQL server. In total, the script returns 4 columns and 1 row of data. How would I use set_variable to return the 4 individual colums to the dialplan?

Below is the code I am currently using while I try to get this working.

AGI Script (var/lib/asterisk/agi-bin/Asterisk_LookupCustomer.php)

[code]#!/usr/bin/php -q

<? $www_host = ''; require 'phpagi.php'; $agi = new AGI; function get_var($name) { global $agi; $result = $agi->get_variable($name); return urlencode(str_replace("'", "''", $result['data'])); } $tagid = get_var('TagIDRequest'); $result = join('', file("http://$www_host/tag_owner_lookup.php?tagid=$tagid")); $agi->set_variable('OwnerFirstName',$result['FirstName']); $agi->set_variable('OwnerLastName',$result['LastName']); $agi->set_variable('OwnerPhone1',$result['Phone1']); $agi->set_variable('OwnerPhone2',$result['Phone2']); ?>[/code]

PHP Page (/var/www/html/tag_owner_lookup.php)

include 'db_inc.php';
$tagid = $_GET['tagid'];
$result = mssql_query("EXECUTE Asterisk_TagOwnerLookup @TAGID=$tagid");
$r = mssql_fetch_array($result);

echo $r;

Dialplan Context

exten => _X.,1,Noop exten => _X.,n,Playback(${PROMPTS}perform-tag-lookup) exten => _X.,n,Set(MESSAGE=MSSQL REQUEST:${TagIDRequest}) exten => _X.,n,GoSub(mightytag-dev-verbose,${IVR-EXTEN},1) exten => _X.,n,AGI(Asterisk_LookupCustomer.php) exten => _X.,n,Set(MESSAGE=FIRST NAME: ${OwnerFirstName}) exten => _X.,n,Set(MESSAGE=LAST NAME: ${OwnerLastName}) exten => _X.,n,Set(MESSAGE=PHONE1: ${OwnerPhone1}) exten => _X.,n,Set(MESSAGE=PHONE2: ${OwnerPhone2}) exten => _X.,n,GoSub(mightytag-dev-verbose,${IVR-EXTEN},1)

As I am new to PHP as well as having limited asterisk knowledge, I appreciate your assistance.



Hi Zach,

I believe you have posted on few forums, I am looking for the same answer . Do you have any success in it ? please share incase you get the answer of the same …