关于DBI的一点忽略的东西

以前写DBI时候,都是形式如下:
# Link Informations And New Class
my $dsn = "dbi:$DATABASE{driver_name}:database=$DATABASE{db_name};
hostname=$DATABASE{db_host};socket=$DATABASE{db_sock};
port=$DATABASE{db_port}";
$dbh     = DBI->connect($dsn, $DATABASE{db_user}, $DATABASE{db_pass},
{'RaiseError' => 1});

我发现对于一台服务器多种mysql的情况:这种调用socket的方式发生了变化,具体发生变化的DBI版本是多少,我无法考究,但是现在变更为:
my $dsn = "dbi:$DATABASE{driver_name}:database=$DATABASE{db_name};
hostname=$DATABASE{db_host};mysql_socket=$DATABASE{db_sock};
port=$DATABASE{db_port}";
my $dbh = DBI->connect($dsn, $DATABASE{db_user}, $DATABASE{db_pass},
{'RaiseError' => 1});
关于perl介绍中还有一块比较使用使用文件方式调用DBI接口:
mysql_read_default_file

These options can be used to read a config file like /etc/my.cnf or ~/.my.cnf. By default MySQL's C client library doesn't use any config files unlike the client programs (mysql, mysqladmin, ...) that do, but outside of the C client library. Thus you need to explicitly request reading a config file, as in

$dsn = "DBI:mysql:test;mysql_read_default_file=/home/joe/my.cnf";
$dbh = DBI->connect($dsn, $user, $password)
使用my.cnf文件的方式可以减少很多的麻烦。 :)
 

Categories

| | 评论(0)

发表评论

August 2012

      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

关于此日记

此日记由 Cnangel 发表于 October 21, 2007 9:56 PM

此Blog上的上一篇日记XP自带的功能强大的搜索工具

此Blog上的下一篇日记批量查询IP引起的警示

首页归档页可以看到最新的日记和所有日记。

归档

Powered by Movable Type 5.14-en