Chinaunix首页 | 论坛 | 博客
  • 博客访问: 466670
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-04-01 15:44:42

用PERL连接MYSQL

#!/bin/perl

    use DBI;

    # Connect to target DB
    my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","username","password", {'RaiseError' => 1});
#lock table
$dbh->do("lock table test write");
    # Insert one row
    my $rows = $dbh->do("INSERT INTO test (id, name) VALUES (1, 'fire9')");

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

    while(my $ref = $sqr->fetchrow_hashref()) {
        print "$ref->{'name'}\n";
    }
#unlock table
$dbh->do("unlock tables");
    $dbh->disconnect();
阅读(441) | 评论(0) | 转发(0) |
0

上一篇:tr 命令

下一篇:如何锁定MYSQL数据表

给主人留下些什么吧!~~