加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl连接mysql的例子

发布时间:2020-12-16 00:37:24 所属栏目:大数据 来源:网络整理
导读:? #!/bin/perl? ? #? load ?module? use?DBI;? ? #? connect ? my?$dbh?=?DBI- connect ( "DBI:mysql:database=db2;host=localhost" ,? "joe" ,? "guessme" ,?{ 'RaiseError' ?=?1});? ? #? execute ? INSERT ?query? my?$ rows ?=?$dbh-do( "INSERT?INTO?us

?

 
 
  1. #!/bin/perl?
  2. ?
  3. #?load?module?
  4. use?DBI;?
  5. ?
  6. #?connect?
  7. my?$dbh?=?DBI->connect("DBI:mysql:database=db2;host=localhost",?"joe",?"guessme",?{'RaiseError'?=>?1});?
  8. ?
  9. #?execute?INSERT?query?
  10. my?$rows?=?$dbh->do("INSERT?INTO?users?(id,?username,?country)?VALUES?(4,?'jay',?'CZ')");?
  11. print?"$rows?row(s)?affected?";?
  12. ?
  13. #?execute?SELECT?query?
  14. my?$sth?=?$dbh->prepare("SELECT?username,?country?FROM?users");?
  15. $sth->execute();?
  16. ?
  17. #?iterate?through?resultset?
  18. #?print?values?
  19. while(my?$ref?=?$sth->fetchrow_hashref())?{?
  20. ????print?"User:?$ref->?";?
  21. ????print?"Country:?$ref->?";?
  22. ????print?"----------?";?
  23. }?
  24. ?
  25. #?clean?up?
  26. $dbh->disconnect();?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读