I was able to test the script, here is what I have:

[CODE]
#!/usr/bin/php -q
<?php

//ini_set("include_path", 
".:../:./includes:../include:/var/lib/asterisk/agi-bin/includes");

//include( "./includes/optimum_config.php" );
$CONF['host']               = 'server';
$CONF['user']               = '';
$CONF['password']           = ''; 
$CONF['database']           = 'testasterisk';


//include( "./includes/constants.php" );
//  Defining constants variables for mysql connect database:
define( "HOST", $CONF['host'] );
define( "USER", $CONF['user'] );
define( "PASSWORD", $CONF['password'] );
define( "DATABASE", $CONF['database'] );

//include( "./includes/functions.php" );
function dba_connect( $query, $connect = 1 ){
      if($connect)
        $link = mysql_connect( HOST, USER, PASSWORD );
        //echo "link: " . $link . " query: " . $query;
        mysql_select_db( DATABASE ) or
          die("Cannot select a Database from the server.");

      if( $result = mysql_query( $query ))
          return $result;
      else
          return 0;
}




// don't let this script run for more than 60 seconds
set_time_limit(60);

// turn off output buffering
ob_implicit_flush(false);

/* turn off error reporting, as it will most likely interfere with
 the AGI interface
*/
error_reporting(0);

// create file handles if needed
if (!defined('STDIN'))
{
define('STDIN', fopen('php://stdin', 'r'));
}
if (!defined('STDOUT'))
{
define('STDOUT', fopen('php://stdout', 'w'));
}
if (!defined('STDERR'))
{
define('STDERR', fopen('php://stderr', 'w'));
}


$query = "select * from balance where bal_cust_id = " . $argv[1];
$result = dba_connect( $query, 1 ) or
              die( "Query: '$query', failed with error message: -- " . 
mysql_error() . " --" );

$record = mysql_fetch_array( $result );
$bal = $record['bal_amount'];

echo "SET VARIABLE BALANCE $bal #\n";

echo "exec BackGround 'tt-monkeys' #\n";

fclose( STDIN );
fclose( STDOUT );
fclose( STDERR );

exit(0);

?>

[/CODE]

extensions.conf:

[test-agi]
exten => 33,1,Answer()
exten => 33,n,Wait(0.5)
exten => 33,n,BackGround(please-enter)
exten => 33,n,BackGround(customer-accounts)
exten => 33,n,Read(ACCOUNT,,4)
;exten => 33,n,BackGround(enter-password)
;exten => 33,n,Read(PASSWORD,,4)
exten => 33,n,AGI(testphp.agi,${ACCOUNT},${PASSWORD})
;exten => 33,n,BackGround(your)
exten => 33,n,BackGround(account-balance-is)
exten => 33,n,SayNumber(${BALANCE})
exten => 33,n,BackGround(dollars)
exten => 33,n,Verbose(".... This is agi status ...${AGISTATUS}...")
exten => 33,n,hangup()

I was able to get the balance from the db table and have asterisk tell the 
caller.

I tried to include some files in agi but kept getting an error that the file 
didn't exist.

I would like to thank you for helping me out with this. Is a good starting 
point.

Now, I have another thing in mind:

Is asterisk or any other program that can work along side * able to say a name 
or any word? For example:

Lets say I have a table with name and last name I would like asterisk to say 
"balance for john doe is 100 dollars"... Is this possible?




      

_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to