Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.
#!/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 &ouml;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: $!";
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 &ouml;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();
it prints out the correct values->
<?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>
what is the error i do? update-> the config file looks like this:
database:xxxxxx db_server:yyy.yyyyy.yy db_user:xxxxxx db_pass:yyyyyy

In reply to problems with reading data from cfg file by pitbull3000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-02-06 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (37 votes). Check out past polls.

    Notices?