pitbull3000 has asked for the wisdom of the Perl Monks concerning the following question:
hi all you noble men,
i just try to read in some data from a config file with following code and try to connect to a mysql database, but i always get the error, script could not connect to database.
if i read in the config file with the following code#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; use HTML::Entities; my $db_config_file = "db.cfg"; my %db_config = (); open CONFIG, ("< $db_config_file") or die "Konnte Datenbank Konfigurat +ions Datei nicht öffnen! $!"; my @config_pairs = <CONFIG>; close CONFIG; foreach (@config_pairs) { chomp $_; my ($key, $value) = split/:/, $_; $db_config{$key} = $value; } my $database = $db_config{'database'}; my $db_server = $db_config{'db_server'}; my $db_user = $db_config{'db_user'}; my $db_pass = $db_config{'db_pass'}; my $dbh = DBI->connect("dbi:mysql:$database:$db_server", "$db_user", " +$db_pass") or die "Konnte Datenbankverbindung nicht herstellen: $!";
it prints out the correct values->#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; use HTML::Entities; my $db_config_file = "db.cfg"; my %db_config = (); open CONFIG, ("< $db_config_file") or die "Konnte Datenbank Konfigurat +ions Datei nicht öffnen! $!"; my @config_pairs = <CONFIG>; close CONFIG; foreach (@config_pairs) { chomp $_; my ($key, $value) = split/:/, $_; $db_config{$key} = $value; } my $database = $db_config{'database'}; my $db_server = $db_config{'db_server'}; my $db_user = $db_config{'db_user'}; my $db_pass = $db_config{'db_pass'}; my $query = new CGI; print $query->header(); print $query->start_html(); print $database . "<br>"; print $db_server . "<br>"; print $db_user . "<br>"; print $db_pass . "<br>"; print $query->end_html();
what is the error i do? update-> the config file looks like this:<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>U +ntitled Document</title> </head><body>db29970540 <br>db07.puretec.de <br>p7397271 <br>8vskBBPH<br></body></html>
database:xxxxxx db_server:yyy.yyyyy.yy db_user:xxxxxx db_pass:yyyyyy
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: problems with reading data from cfg file
by Jazz (Curate) on Sep 10, 2001 at 01:55 UTC | |
Re: problems with reading data from cfg file
by pitbull3000 (Beadle) on Sep 10, 2001 at 02:16 UTC | |
Re: problems with reading data from cfg file
by pitbull3000 (Beadle) on Sep 10, 2001 at 02:45 UTC | |
by Jazz (Curate) on Sep 10, 2001 at 08:03 UTC | |
by pitbull3000 (Beadle) on Sep 10, 2001 at 11:32 UTC |
Back to
Seekers of Perl Wisdom