Das Abholen von Datensätzen

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

catdb.pl
#!/usr/local/bin/perl -w

use Getopt::Std;
use DBI;
use Mysql::Admin qw(dbi_connect);
use strict;

my $cmdname = $0; $cmdname =~ s{.*/}{};
my $usage = "Usage: $cmdname [-d delim] dbdir table\n";
my %opts = (); getopts('d:', \%opts);
my $delim = ' ';
$delim = $opts{'d'} if defined($opts{'d'});
die $usage unless @ARGV == 2;
my $dbdir = shift;
my $table = shift;

my $db = DBI->connect(dbi_connect($dbdir), "", "");
die "$cmdname: unable to connect to db: $DBI::errstr\n"
   unless defined $db;
$db->{RaiseError} = 1;

my $st = $db->prepare("select * from $table");
$st->execute();
my $record;
while (defined($record = $st->fetch())) {
   print join($delim, @{$record}), "\n";
}
$st->finish;

$db->disconnect;

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996, 1998, 1999, 2000 Andreas Borchert, in HTML konvertiert am 07.02.2000