Re: ¿como puedo extraer de una base de datos Mysql Varias fi
Que tal buenas noches.
No he recibido respuestas, así que bueno les cuento que he consultado y me he basado en la pagina http://www.easysoft.com/developer/langu ... art_2.html, en la que he encontrado algunas rutas, sin embargo aunque ya me corre el while, no me permite consultar con una variable ingresada, varias filas.
Le he escrito un mail a perl.org y se los copio haber que opinan.
Perdonen por favor el ingles.
Hi Im Eric.
I'm reading the Perl and DBI tutorial in the web: http://www.easysoft.com/developer/langu ... art_2.html.
In this moment y I have a deployment with Asterisk, it means about an IVR that consult you academic information by dtmf and voice recognition, by enter your Identification.
In this moment I have the 80% of the proyect, beacause I'm not finished the Recognition application, but With the DTMF IVR, I have problems with the MySQL BDD consult, beacuse I can read only the first row.
Im practice some metods but anyone can't help me, and the only tutorial that gave me some way is this.
I know that, with the fetchrow_array I can´t work with a scalar context because it can return the first or last column (this is my problem) and can return undef if there are no more rows or if an error occurs.
In the Tutorial there are other methods, that explain how I can receive some Rows, but I can´t obtain results whit these, beacuse I dont know how to work with AGI in the connector and called multiple rows with a variable input from the dial plan.
Below are my Dial Plan, my BDD and my connector with perl.
I thank your help and attention.
BDD
mysql> select * from alumno;
+------------+----------------+----------------------------+------+--------------+-
| cedula | nombre | materia | nota | adicional |
+------------+----------------+----------------------------+------+--------------+-
| 1724310931 | Eric Alarcon | Tesis | 10 | |
| 1234567890 | Ramiro Meneses | Calculo 1 | 9 | |
| 1234567890 | Ramiro Meneses | Sistemas de Comunicaciones | 8.5 | |
+------------+----------------+----------------------------+------+---------------+-
3 rows in set (0.00 sec)
mysql>
**Dial plan that use the connector.pl
**
exten => s,1,Answer()
exten => s,n,Set(COUNT=1)
exten => s,n,WaitExten(1)
exten => s,n,Background(Grabacion/Bienvenida 8k)
exten => s,n,Background(Grabacion/Cedula)
exten => s,n,WaitExten(5)
exten => _XXXXXXXXXX,1,Set(CEDULA=${EXTEN})
exten => _XXXXXXXXXX,n,Agi(connector.pl)
exten => _XXXXXXXXXX,n,Playback(Grabacion/pertenecea)
exten => _XXXXXXXXXX,n,Festival(${NOMBRE})
exten => _XXXXXXXXXX,n,Festival(${APELLIDO})
exten => _XXXXXXXXXX,n,Goto(menu,s,1)
exten => s,n,WaitExten(2)
exten => i,1,Background(Grabacion/Invalida)
exten => i,n,Goto(dtmf,s,1)
exten => t,1,Set(COUNT=$[${COUNT} + 1])
exten => t,n,GotoIf($[${COUNT} > 3]?4:3)
exten => t,n,Goto(dtmf,s,5)
exten => s,1,Playback(Grabacion/semestre)
exten => s,n,WaitExten(2)
exten => s,n,Festival(${MATERIA})
exten => s,n,WaitExten(1)
exten => s,n,Festival(${NOTA1})
exten => s,n,WaitExten(1)
exten => s,n,Festival(${NOTA2})
exten => s,n,WaitExten(1)
exten => s,n,Festival(${NOTA3})
exten => s,n,WaitExten(1)
exten => s,n,Background(Grabacion/cierrenotas1)
exten => s,n,Background(Grabacion/cierrenotas2)
exten => s,n,WaitExten(10)
exten => *,1,Goto(Todas_notas,s,1)
exten => i,1,Background(Grabacion/Invalida)
exten => i,n,Goto(Notas,s,1)
include => Basicas
include => Basicas_notas
**fetchrow_array
**
With this I can get each of the variables consulted, but does not give me all rows in the variable query. These is that i'm using in this moment.
#!/usr/bin/perl
use strict;
use Asterisk::AGI;
use DBI;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $cedula = $AGI->get_variable('CEDULA');
my $dbh = DBI->connect("DBI:mysql:host=localhost;database=baseuisrael;port=3306","astuser","astpass")
or die "Error en la conexion: $DBI::errstr";
my $sth = $dbh->prepare('SELECT nombre,apellido,materia,nota1,nota2,nota3,seminarios,actividades FROM alumno WHERE cedula = ?');
$sth->execute($cedula) or die ("Error en la consulta");
my ($nombre,$apellido,$materia,$nota1,$nota2,$nota3,$seminarios,$actividades);
while (($nombre,$apellido,$materia,$nota1,$nota2,$nota3,$seminarios,$actividades) = $sth->fetchrow_array) {
$AGI->set_variable('CEDULA', "$cedula");
$AGI->set_variable('NOMBRE', "$nombre");
$AGI->set_variable('APELLIDO', "$apellido");
$AGI->set_variable('MATERIA', "$materia");
$AGI->set_variable('NOTA1', "$nota1");
$AGI->set_variable('NOTA2', "$nota2");
$AGI->set_variable('NOTA3', "$nota3");
$AGI->set_variable('SEMINARIOS', "$seminarios");
$AGI->set_variable('ACTIVIDADES', "$actividades");
}
$sth->finish;
$dbh->disconnect;
**fetchrow_arrayref
**
With the fetchrow_arrayref, the connector give me only the name, and with the fetchrow_hashref is the same. Finnally with the fetchall_arrayref i can't obtain any result.
I dont know how use the AGI with the perl connector, to obtain some rows with an unique variable, like my Identification.
#!/usr/bin/perl
use strict;
use Asterisk::AGI;
use DBI;
my ($dbh,$sth,$ref);
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $cedula = $AGI->get_variable('CEDULA');
my $dbh = DBI->connect("DBI:mysql:host=localhost;database=baseuisrael;port=3306","astuser","astpass")
or die "Error en la conexion: $DBI::errstr";
my $sth = $dbh->prepare('SELECT nombre,apellido,materia,nota1,nota2,nota3 FROM alumno WHERE cedula = ?');
$sth->execute($cedula) or die ("Error en la consulta");
while ($ref = $sth->fetchrow_arrayref) {
$AGI->set_variable('NOMBRE', @{$ref});
$AGI->set_variabl('APELLIDO', @{$ref});
$AGI->set_variable('MATERIA', @{$ref});
$AGI->set_variable('NOTA1', @{$ref});
$AGI->set_variable('NOTA2', @{$ref});
$AGI->set_variable('NOTA3', @{$ref});
}
$sth->finish;
$dbh->disconnect;