PHPAGI problem with get_variable()

General discussions about Asterisk.

Moderators: Moderator, Support

PHPAGI problem with get_variable()

Postby tarekhoury » Wed Dec 31, 2008 5:15 am

hello

im trying to import or get a variable with my agi script using the PHPAGI

my simple DIALPLAN :

exten => 100,1,Asnwer()
exten => 100,n,Set(vartest=20)
exten => 100,n,AGI(getvar.agi )
exten => 100,n,Hangup()

my getvar.agi :

require ('phpagi.php');
$agi = new AGI();
$myvar = $agi->get_variable('vartest');
.
.

then when i try to use the myvar to insert it to my database it doesnt work .. like its empty or something went wrong

NOTE : im using asterisk 1.2

any ideas??? thanks
tarekhoury
Newsterisk
 
Posts: 38
Joined: Tue Dec 09, 2008 7:05 am

Postby tarekhoury » Wed Dec 31, 2008 5:23 am

lol i just solved it

when i inserted the variable to the database i should have used $myvar['data'] not $myvar

hope it helps.
tarekhoury
Newsterisk
 
Posts: 38
Joined: Tue Dec 09, 2008 7:05 am

Postby Dovid » Sun Jan 11, 2009 5:15 am

I was just about to respond when I saw that you figured it out. I banged my head for a few days on this one till I used print_r to figure out how to use it.
Dovid
Salt of the Asterisk
 
Posts: 1452
Joined: Sun Oct 23, 2005 5:28 am
Location: Lakewood, NJ, USA

Postby avs.ceriola » Tue Jan 27, 2009 8:12 am

hello terekhoury,

I just want to ask something about the code you posted:

Where do you want to save the variable you want to get?On what database?

Actually im having a problem on passing a variable coming from asterisk (the callerID) to the sugarCRM, which is web based application, I need it as a key in selecting data in mysql database of sugarCRM, to pop up the detail when someone's calling asterisk..but i cant pass data from asterisk to sugarCRM, maybe you can help me on this matter.

Any help will be appreciated..!!!
Hope you can help me on my thesis..

Thanks in advance!!!
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am

Postby tarekhoury » Thu Jan 29, 2009 6:54 am

hello,

well i save these variables on a mysql database, using an AGI script ( PHP ), so i can display this information in some web interface
tarekhoury
Newsterisk
 
Posts: 38
Joined: Tue Dec 09, 2008 7:05 am

Postby avs.ceriola » Thu Jan 29, 2009 10:05 am

Hello tarekhoury,

So your mygetvar.agi is inside the folder /var/lib/asterisk/agi-bin?

This is your code in
mygetvar.agi :

require ('phpagi.php');
$agi = new AGI();
$myvar = $agi->get_variable('vartest');
...
...
...
So do you have a script after the code you have posted mygetvar.agi that inserting the data you retrieve in the asterisk externsions.conf like

mysql_query("INSERT $myvar[data] INTO database");
after the $myvar = $agi->get_variable('vartest'); or something ?

is it possible?

Like inserting the data to SugarCRM mysql database you retrieve in asterisk?
is it possible?

You can help me alot if i can INSERT data came from asterisk to the database of sugarCRM, because I need the data came from asterisk to search some information about the caller...I need it to have a key to compare in Selecting data, like the callerID...

Thanks in advance tarekhoury!!!
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am

Postby avs.ceriola » Thu Jan 29, 2009 10:08 am

Can I run mysql scripts inside the mygetvar.agi?

Is it possible having a code in mygetvar.agi that inserting some data in the mysql database?

Thanks in advance!!!
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am

Postby tarekhoury » Thu Feb 05, 2009 5:56 am

hello mate

yes you can use mysql commands and insert data to a database, i do it alot using PHP in my agi's

welcome
tarekhoury
Newsterisk
 
Posts: 38
Joined: Tue Dec 09, 2008 7:05 am

About sql in agi

Postby avs.ceriola » Fri Feb 06, 2009 9:45 am

Hello tarekhoury,

So i will put the sql scripts on /var/lib/asterisk/agi-bin/ then my scripts?

So i have to set up the connection of my database in sugar, for opening the database and have some query on my agi?

If you dont mind, can you send me some of your scripts in your agi-bin that is using sql scripts and accesing some database? I really need someone who can guide me on this...I really appreciate your help..

When some one call, all i need to do is update the database of my sugar or something like inserting the the caller ID of the caller then have a pop up of his data?Am i right?

Can you guide me on what to do like giving me some steps on what to do first?

I will really appreciate your help...Please help me on my thesis...

Thanks tarekhoury!!!
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am

Pop up for inbound call

Postby avs.ceriola » Fri Feb 06, 2009 9:56 am

Do you now what is the best way to use when you want to pop up a data to the SugarCRM when someones calling the asterisk?

Can you share it with me? By the way my email add is avs.ceriola@gmail.com...If want to send some codes that i have ask you, i forgot it to post in my last reply.

I will really appreciate your help tarekhoury!!!Please help me on this...
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am

Postby tarekhoury » Mon Feb 09, 2009 2:48 am

hello

well i dunno about the SugarCRM, when i want to insert for example the callerID in a database, i do a simple php DB connection then run mysql_query and insert that CallerID to the wanted database, if what you are asking for is how to do the connection and the query then here is a very simple example :

#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit(5);
require ('phpagi.php');
$agi = new AGI();
$callernum=$agi->get_variable("CALLERID(number)");
$callernum=$callernum['data'];
$con=mysql_connect("host","dbusername","dbpassword");
$db=mysql_select_db("dbname",$con);
$sql="INSERT INTO tblname (`callerid`) VALUES ('$callernum)";
mysql_query($sql);
mysql_close($con);
?>

that will be ur AGI script that you run everytime a user calls or how ever u want to use it for

hope it helps
tarekhoury
Newsterisk
 
Posts: 38
Joined: Tue Dec 09, 2008 7:05 am

Postby avs.ceriola » Mon Feb 09, 2009 11:54 am

Hello tarehoury,

Thanks for the reply, i actually implemented some mysql procedures, like connecting to the database..And it works in localhost.....

But i have something to ask, can i connect to the database of an online site, like connecting on online database in using phpagi codes? like mysql_connect('online database path', "root", "");?

Actually i havent tried it in online cuz im using my localhost as a database...

thanks for the help,
best regards
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am

Postby mbruni » Tue Feb 10, 2009 2:54 am

But i have something to ask, can i connect to the database of an online site, like connecting on online database in using phpagi codes?

You can do this, if the configuration of the remote database server allows it.

Cheers.

Marco Bruni
www.marcobruni.net
mbruni
Astmaster
 
Posts: 957
Joined: Thu Dec 21, 2006 10:56 pm
Location: Arezzo, Italy

Postby avs.ceriola » Tue Feb 10, 2009 12:41 pm

Hello Marco,

Thanks for the reply.

Can you teach me how to configure my xampp in ubuntu to access remote databases? Cause i can only access my localhost database for now.

Best regards..
avs.ceriola
Newsterisk
 
Posts: 11
Joined: Tue Jan 27, 2009 7:31 am


Return to Asterisk General

Who is online

Users browsing this forum: No registered users and 1 guest