免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1616 | 回复: 1
打印 上一主题 下一主题

DBI 怎样取出mysql数据库数据 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-14 22:07 |只看该作者 |倒序浏览
  1. use strict;
  2. use warnings;
  3. use LWP::UserAgent;
  4. use Encode qw/encode decode/;  
  5. use Web::Scraper;
  6. use DBI;
  7. use File::Find;
  8.    
  9.    my $user='root';
  10.    my $pass='123456';
  11.    my $db='DBI:mysql:crawl:localhost';
  12.    print ("It's connecting the mysql.....\n");
  13.    my $dbh= DBI->connect($db,$user,$pass) or die "&LOG('无法连接数据库:$!')";
  14.    print ("It's connetct sucessfully!!\n");
  15.    
  16.       my $sth = $dbh->prepare("select time from crawl_main_table where keyword ='广中医' order by time desc limit 1");     
  17.       my $quoted_string = $dbh->do("desc crawl_main_table");
  18.       print $quoted_string;
复制代码
怎样取出数据库里第一行数据呢?上面的代码是错误的。。。

论坛徽章:
0
2 [报告]
发表于 2011-11-14 22:36 |只看该作者
  1.       my $sth = $dbh->prepare("select time from crawl_main_table where keyword ='广中医' order by time desc limit 1");   
  2.       $sth->execute();
  3.       while ( my @row = $sth->fetchrow_array()) {
  4.       print "Row: @row \n"; }
复制代码
这样就可以了没有仔细看DBI模块
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP