DBI Mysql Select
2002-03-11 21:18:49
Category: perl:database
Description: Print all the rows from a mysql table using DBI to retrieve the data.
Author: detour
Viewed: 5157
Rating: (29 votes)


#!/usr/bin/perl
#
# dbisel.pl written by detour@metalshell.com
#
# Print all the values from a mysql table using
# DBI to retrieve the data.
#
# http://www.metalshell.com/
#
 
use DBI;
 
$dbname = "mydatabase";
$user = "fred";
$pass = "secret123";
$table = "mytable";
 
my $db = DBI->connect("DBI:mysql:$dbname", $user, $pass);
 
$DBI::result = $db->prepare("select * from $table");
$DBI::result->execute();
 
while(@row = $DBI::result->fetchrow_array) {
  print @row, "\n";
}
 
$db->disconnect;