无法在@INC 中找到 DBD/ODBC.pm@INC 包含:/usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor )

问题描述

#!/usr/bin/perl
use strict;
use DBI;
use warnings;

my $user = "database_user";
my $pass = "database_password";

my $server = "ip";
my $database_name = "db";

my $connectString = "driver={GBase ODBC 8.3 Driver};server=$server;database=$database_name;uid=$user;pwd=$pass";
my $dbh = DBI->connect("DBI:ODBC:$connectString")|| die "Connect Failed: $DBI::errstr\n";

当我尝试执行 a.pl 脚本连接数据库时,出现以下错误

install_driver(ODBC) Failed: Can't locate DBD/ODBC.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 3) line 3.
Perhaps the DBD::ODBC perl module hasn't been fully installed,or perhaps the capitalisation of 'ODBC' isn't right.
Available drivers: DBM,ExampleP,File,Gofer,Proxy,sqlite,Sponge.

然后我尝试运行 perl -e 'use DBD::ODBC;' 并得到同样的错误

在@INC 中找不到 DBD/ODBC.pm(@INC 包含: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) 在 -e 第 1 行。开始 失败——编译在 -e 第 1 行中止。

有人可以帮我解决吗?

解决方法

您缺少 DBD::ODBC 模块。使用工具安装 package from CPAN

您可以使用 cpan 可执行文件或最好使用 cpanm

$ cpan DBD::ODBC