Wednesday, January 23, 2013

Perl with SQLServer -> =)


use DBI;

my $dsn = 'DBI:ODBC:Driver={SQL Server}';
my $host = 'WINSRV';
my $database = 'Relatorios';
my $user = 'sa';
my $auth = 'm1f1g1f4$';


my $dbh = DBI -> connect( "dbi:ODBC:driver={SQL Server};server={$host};Trusted Connection=yes, $user, $auth { PrintError => 0,RaiseError => 0,}") or die "\n\nthe mssql connection died with the following error: \n\n$DBI::errstr\n\n";

my $sth = $dbh->prepare('SELECT *  FROM sys.tables');

$sth->execute();

while(my @result = $sth->fetchrow_array() ){
        print join ("\t",@result),"\n";
}

$dbh->disconnect();




0 comentários:

Post a Comment