SHARE
TWEET

Untitled

a guest May 19th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Brenbot execute_query sub
  2.  
  3. sub execute_query
  4. {
  5.     $| = 1;
  6.     my $sth;
  7.     my $query = shift;
  8.     my $flag = shift;
  9.  
  10.     #print "DEBUG: $query\n";
  11.     $sth = $dbh->prepare ( "$query" );
  12.     $sth -> execute;
  13.    
  14.     # If the flag is undef or 0 return the result of the query
  15.     if (!$flag)
  16.     {
  17.         my $attrib_nr = 0;
  18.         my @array_of_hash_refs;
  19.         my @new_array;
  20.         my $db_line;
  21.    
  22.         while ($db_line = $sth->fetchrow_hashref())
  23.         {
  24.             $array_of_hash_refs[$attrib_nr] = $db_line;
  25.             $attrib_nr++;
  26.         }
  27.         undef $attrib_nr;
  28.        
  29.         foreach (@array_of_hash_refs)
  30.         {
  31.             my %hash = %$_;
  32.             my %hash_lc;
  33.             while ((my $k, my $v) = each %hash)
  34.             {
  35.                  $k = lc($k);
  36.                  $hash_lc{$k} = $v;
  37.             }
  38.             push (@new_array,\%hash_lc);
  39.         }
  40.        
  41.         # Clear the hash refs array by setting its length to -1
  42.         $#array_of_hash_refs = -1;
  43.        
  44.         return (@new_array);
  45.     }  
  46. }
  47.  
  48.  
  49. Usually you would do something like
  50.  
  51.             my $query2; #SQL Query
  52.             my @row2; #SQL Data Row
  53.  
  54.             $query2 = $dnsbansdbh->prepare ( "SELECT dns FROM host WHERE name='".$name."'" );
  55.             $query2->execute();
  56.             if ( @row2 = $query2->fetchrow_array )
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top