eygle.com   eygle.com
eygle.com eygle
eygle.com  
 

« eygle.com完成建站以来最大的一次迁移 | Blog首页 | "软件"、硬件都需要健康检查 »

使用Perl连接Mysql数据库

网站后台数据库转为Mysql,现在使用Perl连接数据库就方便多了。

通过DBI,Perl可以很容易的连接到数据库:

#!/bin/perl

use DBI;

# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=eygle;host=localhost","username","password", {'RaiseError' => 1});

# Insert one row
my $rows = $dbh->do("INSERT INTO test (id, name) VALUES (1, 'eygle')");

# query
my $sqr = $dbh->prepare("SELECT name FROM test");
$sqr->execute();

while(my $ref = $sqr->fetchrow_hashref()) {
    print "$ref->{'name'}\n";
}

$dbh->disconnect();

执行结果:

[root@eygle ~]# perl test.cgi
eygle

以后很多统计数据可以直接通过Perl写入Mysql数据库,操作起来方便多了。
看来这次迁移是值得的:)

-The End-


历史上的今天...
      >> 2008-12-12文章:
      >> 2005-12-12文章:
             How to maintain Oracle10g Recyclebin?
             Definer and Invoker Rights
      >> 2004-12-12文章:

By eygle on 2006-12-12 15:33 | Comments (3) | Del.icio.us | Google | Web | Edit |Pageviews:

无觅

搜索本站:

3 Comments

恭喜恭喜

最近一直关注你的网站,多跟你学习学习.

发表留言



CopyRight © 2004~2012 eygle.com, All rights reserved.
数据恢复·紧急救援·联系我们:电话:010-59459859 手机:13911812803 邮件:eygle@eygle.com|MSN联系:eygle@hotmail.com