页面

安装DBI::mysql

1.安装新的dbi
  自己安装的mysql是5.1的,
  如果dbi不是新的也会报错.说mysql.so有符号找不到.

2.安装DBD::mysql
  make test时会报一些错,但可以不管,直接make install.
  后来google发现出现make [test_dyna] error 255之类的错是有module版本不够高.

btw:
cpan的使用
默认情况下,cpan无法使用,会报zip什么的找不到,google看到篇文章,说要安装一堆压缩/解压缩的module.找不到刚才那链接了:P

真不行了,可以直接从源码装.

一个测试的hello world程序:
#!/usr/bin/perl -w

use DBI;
use strict;

# Connection parameters
my $user= "";
my $password= "";
my $host= "localhost";

# Establish the connection which returns a DB handle
my $dbh= DBI->connect("dbi:mysql:database=mysql;host=$host;dbi:mysql:mysql_socket=/home/tangyi/bin/var/mysql.sock",$user,$password)
    or die $DBI::errstr;

# Prepare the SQL statement
my $sth= $dbh->prepare("SELECT VERSION()")
    or die $DBI::errstr;

# Send the statement to the server
$sth->execute();

my $numRows = $sth->rows;
print "Rows returned: $numRows\n";

my @row;
while ( @row = $sth->fetchrow_array )
    {
    print "@row\n";
    }
# Close the connection
$dbh->disconnect or die $DBI::errstr;
DBI->installed_versions;
my @ary  = DBI->installed_versions;
my %hash = DBI->installed_versions;
foreach (@ary) {
    print;
    print "\t";
}
print "\n";
while (my ($k,$v) = each %hash) {

    print $k . "\t" . $v . "\n";
}

没有评论: