如何从 Perl 脚本在 SQL Server 2005 上执行 SELECT?
最佳答案
您将需要使用 DBI,并且最好使用 ( CPAN ) 中的 DBD::ODBC 提供程序。如果您不了解 DBI,那么您需要阅读相关内容。有本书( Programming the Perl DBI )很旧但仍然有效。
然后类似下面的内容:
use strict;
use warnings;
use DBI;
# Insert your DSN's name here.
my $dsn = 'DSN NAME HERE'
# Change username and password to something more meaningful
my $dbh = DBI->connect("DBI:ODBC:$dsn", 'username', 'password')
# Prepare your sql statement (perldoc DBI for much more info).
my $sth = $dbh->prepare('select id, name from mytable');
# Execute the statement.
if ($sth->execute)
{
# This will keep returning until you run out of rows.
while (my $row = $sth->fetchrow_hashref)
{
print "ID = $row->{id}, Name = $row->{name}\n";
}
}
# Done. Close the connection.
$dbh->disconnect;
关于sql-server-2005 - 从 Perl 连接到 SQL Server 2005 并执行 SELECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/896985/