daily pastebin goal
27%
SHARE
TWEET

test_dbi

a guest Jan 25th, 2016 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use DBI;
  2. use DBD::mysql;
  3.  
  4. sub LoadMysql{ 
  5.     #::: Config Variables
  6.     my $confile = "eqemu_config.xml";
  7.     open(F, "<$confile") or die "Unable to open config: $confile\n";
  8.     my $indb = 0;
  9.     while(<F>) {
  10.         s/\r//g;
  11.         if(/<database>/i) { $indb = 1; }
  12.         next unless($indb == 1);
  13.         if(/<\/database>/i) { $indb = 0; last; }
  14.         if(/<host>(.*)<\/host>/i) { $host = $1; }
  15.         elsif(/<username>(.*)<\/username>/i) { $user = $1; }
  16.         elsif(/<password>(.*)<\/password>/i) { $pass = $1; }
  17.         elsif(/<db>(.*)<\/db>/i) { $db = $1; }
  18.     }
  19.     $database_name = $db;
  20.     #::: DATA SOURCE NAME
  21.     $dsn = "dbi:mysql:$db:localhost:3306";
  22.     #::: PERL DBI CONNECT
  23.     $connect = DBI->connect($dsn, $user, $pass);
  24.     return $connect;
  25. }
  26.  
  27.  
  28. my $dbh = LoadMysql();
  29.  
  30. my $sth = $dbh->prepare("SELECT MAX(id) FROM items");
  31. $sth->execute();
  32. my $max = $sth->fetchrow_array();
  33. print "Max item ID is $max\n";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand