Need a bit of help with this script. I want to take a list of item names from a text file then fetch there associated item id's from the database then output both the item names and item id's into a specific format as indicated below.
Code:
use DBI;
my $db = "peq";
my $user = "root";
my $pass = "password";
my $host = "localhost";
my $source = "DBI:mysql:database=$db;host=$host";
my $dbh = DBI->connect($source, $user, $pass) || die "Could not create db handle\n";
sub get_item {
my $item_name;
my $item_id;
my $sth = $dbh->prepare("SELECT * FROM items WHERE `name`=$item_name and `id`=$item_id");
$sth->execute();
########Something along the lines of fetch() is suppose to go here
########not sure what though
}
open (FILE, 'data.txt');
while (<FILE>) {
chomp;
########take item name from file pass it through get_item() retrieving item id
########then take the item name and the fetched item id
########outputting it into the desired format
open (MYFILE2, '>>data2.txt');
print MYFILE2 "INSERT INTO `lootdrop_entries` (`lootdrop_id`, `item_id`, `item_charges`, `equip_item`, `chance`) VALUES (x, $id, 1, 0, z); /* $name */\n";
}
close (MYFILE);
close (MYFILE2);