Example Perl Program
时间:2010-01-23 来源:admin126com
Example Perl Program
#!/usr/bin/perl use DBI; use strict; my $conn = DBI->connect("dbi:Pg:dbname=test"); my ($first_name, $last_name, $hired_at); my (@row); $conn->do("SET DateStyle = 'European'"); my $query = $conn->prepare( "SELECT first_name, last_name, hired_at" . " FROM employees" . " ORDER BY last_name, first_name" ); $query->execute(); print sprintf("%-40s%-20s", "Name:", "Hired At:"), "\n"; print "-" x 60 . "\n"; while (@row = $query->fetchrow_array()) { ($first_name, $last_name, $hired_at) = @row; print sprintf("%-40s%-20s", $first_name . " " . $last_name, $hired_at), "\n"; } undef($query); $conn->disconnect(); $conn = undef;
相关阅读 更多 +