参考连接
odbc.ini文件部分内容
[ODBC]
…
…
[mydsn]
driver=/opt/xxx/xx.so
…
…
sub dbi_connect { # mydsn需配置,查看odbc.ini里面配置的名称,如为mydsn my $DSN="mydsn"; my $user="testuser"; my $pass="shure123"; my $dbh = DBI->connect("dbi:ODBC:$DSN", $user, $pass, { RaiseError => 1, odbc_cursortype => 2}); my $sth = $dbh->prepare("one statement"); my $sth2 = $dbh->prepare("two statement"); $sth->execute; my @row; while (@row = $sth->fetchrow_array) { $sth2->execute($row[0]); } }
my $h = DBI->connect(‘dbi:ODBC:DRIVER={SQL Server}’, “username”, “password”,
{odbc_driver_complete => 1});
终端输入 env,查看odbc.ini所在的路径
查看odbc.ini是否配置了如名为Teradata,并指定了drvier的路径,如
[Teradata]
driver=/opt/xxx/xx.so
此处可以driver名称可以使用Teradata
sub dynamicConnect { my ($user,$pwd,$IP)=@_; # 若指定端口可以设置host格式为$host='ip,port',当前这里不指定端口 my $host=$IP; my $driver='DBI:ODBC:Driver={Teradata}'; my $dbc='DBCName=AAA'; my $db='Database='; my $defaultDB='DefaultDatabase='; my $myDSN="$driver;$host;$dbc"; # 或者$myDSN="$driver;$host;$dbc;$db;LastUser=;Username=;Password=;$defaultDB"; my $dh = DBI->connect(myDSN, $user, $pwd, {AutoCommit=>1,PrintError=>1,RaiseError=>0}); #unless(defined($dh)) { #sleep(30); #} }