我正在尝试运行perl脚本以将数据插入远程SQL Server数据库。我已经安装了DBI模块并运行了以下命令:
aptitude install tdsodbc
dpkg-reconfigure tdsodbc
aptitude install unixodbc-dev
cpan DBD::ODBC
安装DBD:ODBC
驱动程序。
这是我在/var/log/apache2/error.log
:
[Fri Jul 29 13:51:53.838633 2016] [cgi:error] [pid 27482] [client MY_IP:49390] AH01215: Perhaps the DBD::ODBC perl module hasn't been fully installed,, referer: http://MY_IP:8080/
[Fri Jul 29 13:51:53.838649 2016] [cgi:error] [pid 27482] [client MY_IP:49390] AH01215: or perhaps the capitalisation of 'ODBC' isn't right., referer: http://MY_IP:8080/
[Fri Jul 29 13:51:53.838667 2016] [cgi:error] [pid 27482] [client MY_IP:49390] AH01215: Available drivers: DBM, ExampleP, File, Gofer, Proxy, Sponge, mysql., referer: http://MY_IP:8080/
[Fri Jul 29 13:51:53.838681 2016] [cgi:error] [pid 27482] [client MY_IP:49390] AH01215: at /var/www/html/src/cgi-bin/login.pl line 88., referer: http://MY_IP:8080/
[Fri Jul 29 13:51:53.854105 2016] [cgi:error] [pid 27473] [client MY_IP:49386] AH01215: install_driver(ODBC) failed: Can't locate DBD/ODBC.pm in @INC (you may need to install the DBD::ODBC module) (@INC contains: GeoIP/Geo-IP-1.38/lib/ /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl) at (eval 177) line 3., referer: http://MY_IP:8080/
以下是我与数据库连接的代码(login.pl
):
my $database = "<DB NAME>";
my $host = "<REMOTE_IP>";
my $username = "<USERNAME>";
my $password = "<PASSWORD>";
my $dbs = "dbi:ODBC:DRIVER={FreeTDS};SERVER={$host};DATABASE=$database";
# Invoke connection to MySQL
#my $connection = ConnectToMySql($database, $host, $username, $password);
my $connection = DBI->connect($dbs,
$username,
$password,
{RaiseError => 1, AutoCommit => 1}) or die ("Can't connect to database $database on $host: " . $DBI::errstr . "\n");
运行cpan DBD::ODBC
时的消息:
This looks like a unixodbc type of driver manager.
Looking for odbcinst
Found odbcinst in /usr/bin
odbcinst -j reports:
unixODBC 2.2.14
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/openflow/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Please note these files as they are where you define your ODBC drivers and data sources.
Looking for odbc_config to get cflags
odbc_config not found - ok
Warning: LD_LIBRARY_PATH= doesn't include /usr/lib/x86_64-linux-gnu
Checking if your kit is complete...
Looks good
Using DBI 1.63 (for perl 5.018002 on x86_64-linux-gnu-thread-multi) installed in /usr/lib/perl5/auto/DBI/
Using DBI 1.63 (for perl 5.018002 on x86_64-linux-gnu-thread-multi) installed in /usr/lib/perl5/auto/DBI/
Writing Makefile for DBD::ODBC
Writing MYMETA.yml and MYMETA.json
Warning: not all required environment variables are set.
Warning: Will not be able to run tests as you have not defined
all of DBI_DSN, DBI_USER and DBI_PASS environment variables.
MJEVANS/DBD-ODBC-1.52.tar.gz
make -- NOT OK
'YAML' not installed, will not store persistent state
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible