These forums are read-only!
Fetching values in Perl
  • Hi all,
    I have written a query like this.
    ----------------------------------------------------------

    $dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password");

    $statement = "SELECT patient_intime from $table_name where patient_intime=$ARGV[0])";


    ----------------------------------------------------------
    I want all the "patient_intime" values to be retreived, where there are other columns(fields) also.
    Pls suggest me how to proceed.

    Thanks in advance.
    Padmaja T N.
  • try perldoc DBI from command line for more information on how to use DBI, or perldoc perldoc for help with perldoc.

         $sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?");
    
         $sth->execute( $baz );
    
         while ( @row = $sth->fetchrow_array ) {
           print "@row\n";
         }
    
  • BTW, don't code it this way if $table_name or $ARGV[0] is taken from user input. That creates a big security hole. Use "?" in sqls instead.
  • padmaja3, not escaping user provided parameters could open your script to an attack known as sql injection. If you use $dbh->prepare() and the ? placeholder for parameters you can avoid that security hole.

  • Thanks for the response, but I'm passing values from Asterisk to Perl. Thats y I'm using $table_name and $ARGV[0].

    In extensions.conf
    **************************
    exten => 444,18,AGI(insert_db.pl|${intime})