in reply to connect_with_option_file

It looks like you cannot count on using "$ENV{HOME}" to specify the path to your ".my.cnf" file. Figure out what the absolute path to the intended file is (e.g. it might be "/home/whoever_you_are/.my.cnf"). Remember that the CGI script runs as whatever "user" owns the web server process, and it's likely that "$ENV{HOME}" is undefined for that user.

Replies are listed 'Best First'.
Re^2: connect_with_option_file
by gmacfadden (Sexton) on Jul 27, 2005 at 01:10 UTC
    Thx for replying graff. I implemented your suggestion as follows:
    sub connect_with_option_file { $dsn .= ";mysql_read_default_file=home/gmacfadd/public_html/cg +i-bin/dubois/.my.cnf"; return (DBI->connect ($dsn, undef, undef, {PrintError => 0, RaiseError =>1})); }
    I also moved the option file (.my.cnf) to the following directory on my hosting server: home/gmacfadd/public_html/cgi-bin/dubois When I executed, here is the error I received:

    Software error: DBI connect('database=gmacfadd_webdb;host=localhost;mysql_read_default_file=home/gmacfadd/public_html/cgi-bin/dubois/.my.cnf','',...) failed: Access denied for user: 'gmacfadd@localhost' (Using password: NO) at /home/gmacfadd/public_html/cgi-bin/dubois/WebDB.pm line 20

    The fact the server thinks I'm gmacfadd@localhost instead of gmacfadd_webdev2 is puzzling...possibly meaning that it can't find my option file - but it is there!

      Try putting an initial slash in that path string, to make it absolute:
      $dsn .= ";mysql_read_default_file=/home/gmacfadd/public_html/cgi-bin/d +ubois/.my.cnf";
      (update: and if that doesn't work, be sure to check permissions along every step of that path; it needs to be readable by both the web server and the mysql daemon (which typically runs with username "mysql"), so rwxr-xr-x on each directory in the path, and rw-r--r-- on the config file itself.)
        Thanks graff. The initial slash did the trick, I'll show my appreciation now by going to the offering plate.