Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use DBI;
- use DBD::mysql;
- sub LoadMysql{
- #::: Config Variables
- my $confile = "eqemu_config.xml";
- open(F, "<$confile") or die "Unable to open config: $confile\n";
- my $indb = 0;
- while(<F>) {
- s/\r//g;
- if(/<database>/i) { $indb = 1; }
- next unless($indb == 1);
- if(/<\/database>/i) { $indb = 0; last; }
- if(/<host>(.*)<\/host>/i) { $host = $1; }
- elsif(/<username>(.*)<\/username>/i) { $user = $1; }
- elsif(/<password>(.*)<\/password>/i) { $pass = $1; }
- elsif(/<db>(.*)<\/db>/i) { $db = $1; }
- }
- $database_name = $db;
- #::: DATA SOURCE NAME
- $dsn = "dbi:mysql:$db:localhost:3306";
- #::: PERL DBI CONNECT
- $connect = DBI->connect($dsn, $user, $pass);
- return $connect;
- }
- my $dbh = LoadMysql();
- my $sth = $dbh->prepare("SELECT MAX(id) FROM items");
- $sth->execute();
- my $max = $sth->fetchrow_array();
- print "Max item ID is $max\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement