PHPAGI problem with get_variable()

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

lol i just solved it

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

hope it helps.

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.

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!!!

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

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!!!

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!!!

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

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!!!

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…

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

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

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

Cheers.

Marco Bruni
www.marcobruni.net

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…