免费注册 查看新帖 |

Chinaunix

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

请教Perl中DBI的connect的username/password用法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-26 14:13 |只看该作者 |倒序浏览
DBI中connect用法是:$dbh = DBI->connect("DBIracle",$username,$pw);
但常见的如下:(公司很早的别人写的也是如此)
$dbh = DBI->connect('dbi:Oracle:',"test/test@(DESCRIPTION=
                                                                (ADDRESS=
                                                                 (PROTOCOL=TCP)
                                                                 (HOST=xx.xx.xx.com)
                                                                 (PORT=1521)
                                                                 )
                                                                (CONNECT_DATA=
                                                                 (SID=PROD)
                                                                 )
                                                                )" )

其中test/test为username/password, 但后面的具体含义是什么呢?

(不好意思,刚才还在编辑的时候,不小心回车就发了出来,最早看到的写的不完整)

[ 本帖最后由 charseller 于 2006-7-26 14:59 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-07-26 14:16 |只看该作者
i don't know what do you want


  1.   
  2. =head1 NAME

  3. DBI - Database independent interface for Perl

  4. =head1 SYNOPSIS

  5.   use DBI;

  6.   @driver_names = DBI->available_drivers;
  7.   %drivers      = DBI->installed_drivers;
  8.   @data_sources = DBI->data_sources($driver_name, \%attr);

  9.   $dbh = DBI->connect($data_source, $username, $auth, \%attr);

  10.   $rv  = $dbh->do($statement);
  11.   $rv  = $dbh->do($statement, \%attr);
  12.   $rv  = $dbh->do($statement, \%attr, @bind_values);

  13.   $ary_ref  = $dbh->selectall_arrayref($statement);
  14.   $hash_ref = $dbh->selectall_hashref($statement, $key_field);

  15.   $ary_ref  = $dbh->selectcol_arrayref($statement);
  16.   $ary_ref  = $dbh->selectcol_arrayref($statement, \%attr);

  17.   @row_ary  = $dbh->selectrow_array($statement);
  18.   $ary_ref  = $dbh->selectrow_arrayref($statement);
  19.   $hash_ref = $dbh->selectrow_hashref($statement);

  20.   $sth = $dbh->prepare($statement);
  21.   $sth = $dbh->prepare_cached($statement);

  22.   $rc = $sth->bind_param($p_num, $bind_value);
  23.   $rc = $sth->bind_param($p_num, $bind_value, $bind_type);
  24.   $rc = $sth->bind_param($p_num, $bind_value, \%attr);

  25.   $rv = $sth->execute;
  26.   $rv = $sth->execute(@bind_values);
  27.   $rv = $sth->execute_array(\%attr, ...);

  28.   $rc = $sth->bind_col($col_num, \$col_variable);
  29.   $rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);

  30.   @row_ary  = $sth->fetchrow_array;
  31.   $ary_ref  = $sth->fetchrow_arrayref;
  32.   $hash_ref = $sth->fetchrow_hashref;

  33.   $ary_ref  = $sth->fetchall_arrayref;
  34.   $ary_ref  = $sth->fetchall_arrayref( $slice, $max_rows );

  35.   $hash_ref = $sth->fetchall_hashref( $key_field );

  36.   $rv  = $sth->rows;

  37.   $rc  = $dbh->begin_work;
  38.   $rc  = $dbh->commit;
  39.   $rc  = $dbh->rollback;

  40.   $quoted_string = $dbh->quote($string);

  41.   $rc  = $h->err;
  42.   $str = $h->errstr;
  43.   $rv  = $h->state;

  44.   $rc  = $dbh->disconnect;

  45. I<The synopsis above only lists the major methods and parameters.>

  46.   
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-07-26 14:24 |只看该作者
不好意思,问题还在编辑的时候拼音输入多了个回车就发了出去,已经更新了

论坛徽章:
0
4 [报告]
发表于 2006-07-26 14:27 |只看该作者
个人感觉就是Oracle的tnsnames.ora client定义,但DBI中何处要求了?

论坛徽章:
0
5 [报告]
发表于 2006-07-26 15:18 |只看该作者
也许是调用oracle DBI会在本机查询tnsnames.ora,如果这里定义了,就直接使用?

论坛徽章:
0
6 [报告]
发表于 2006-07-26 15:46 |只看该作者
举个例子


还是看看 perl-dbi的书吧

  1.    

  2.     my %attr = (
  3.         PrintError => 1,
  4.         RaiseError => 1,
  5.         AutoCommit => 0
  6.     );
  7.     my $dbh;
  8.     my $times=1;
  9.     until ( $dbh = DBI->connect(
  10.                 $config->{$db_name}->{'odbc_dsn'},
  11.                 $config->{$db_name}->{'db_user'},
  12.                 $config->{$db_name}->{'db_pwd'},
  13.                 \%attr))
  14.     {
  15.         warn "Can't connect :$DBI::errstr ,retrying $times times\n";
  16.         if( $times >=3 )
  17.         {
  18.             &PrintLog("Can't connect :$DBI::errstr",'ConnectDB');
  19.             return undef;
  20.         }
  21.         $times++;
  22.         sleep 60;
  23.     }

复制代码

论坛徽章:
0
7 [报告]
发表于 2006-07-27 10:34 |只看该作者
翻了半天perl-dbi,没有找到与这个相关的的,难道约定成俗用法?反正俺也只有依葫芦画瓢了:)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP