简体   繁体   English

从CGI脚本Perl访问用于DBI连接的配置文件的正确方法

[英]Correct way to access config files for DBI connection from CGI script Perl

Hi I am relativley new to Perl and DBI programming, and just started learning CGI. 嗨,我是Perl和DBI编程的新手,刚刚开始学习CGI。 I want to access a Mysql databases via a perl cgi script but I dont want to store the configuration variables (username , password etc ) in the actual script in the cgi-bin. 我想通过perl cgi脚本访问Mysql数据库,但是我不想在cgi-bin的实际脚本中存储配置变量(用户名,密码等)。 I can use a require '/path/to/configfile.pl' statement but only without using use strict , which I dont like. 我可以使用require '/path/to/configfile.pl'语句,但只能不使用我不喜欢的use strict I am hoping someone can tell me what is the correct and safe way for including config files in this specific situation. 我希望有人可以告诉我在这种特定情况下包括配置文件的正确和安全的方法是什么。

If you are using Mysql,then this will work: 如果您使用的是Mysql,则可以使用:

my $dbh = DBI->connect("dbi:mysql:mysql_read_default_file=$config_file;mysql_read_default_group=$group",undef,undef,{});

And the config file should be like this: 并且配置文件应如下所示:

[group_name]
database=my_db
host=X.X.X.X
user=my_user
password=my_password
port=XXXX
[another_group]
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM