gmacfadden has asked for the wisdom of the Perl Monks concerning the following question:
I've put the following connection code information in a library function module called WebDB.pm and placed it in the directory home/gmacfadd/public_html/cgi-bin/dubois on my hosted site:$dbh = DBI->connect("DBI:mysql:gmacfadd_webdb:localhost","gmacfadd +_webdev2","webdevpass2", {PrintError => 0, RaiseError => 1});
In accordance with the above code, the hardwired connection methods using name and password also work fine. It is the with connect_with_otion_file that I'm having difficulty. I have duly created the .my.cnf file in my root directory (C:/.my.cnf) on my Windows XP system, specifiying the following client program connection parameters:#! /usr/bin/perl -wT package WebDB; use strict; use DBI; my $host_name = "localhost"; my $db_name = "gmacfadd_webdb"; my $dsn = "DBI:mysql:database=$db_name;host=$host_name"; # Connect to MySQL server using hardwired name and password sub connect { return (DBI->connect ($dsn, "gmacfadd_webdev2", "webdevpass2", {PrintError => 0, RaiseError =>1})); } sub connect_with_option_file { $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf"; return (DBI->connect ($dsn, undef, undef, {PrintError => 0, RaiseError =>1})); } 1; #return true
I have created and confirmed that the aforementioned user and password are existing in mySQL. When I then try to run the CGI containing the following:[client] user="gmacfadd_webdev2" password="webdevpass2"
I receive the following error message: DBI connect('database=gmacfadd_webdb;host=localhost; mysql_read_default_file=/.my.cnf','',...) failed: Access denied for user: 'gmacfadd@localhost' (Using password: NO) at /home/gmacfadd/public_html/cgi-bin/dubois/WebDB.pm line 20 Can you please help me correct my problem?#! /usr/bin/perl -wT # intro7b.cgi - use WebDB to connect use strict; # FORCE ALL VARIABLES TO BE DECLARED BEFORE + USE use DBI; # IMPORT THE DATABASE INTERFACE METHODS use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use lib qw(/home/gmacfadd/public_html/cgi-bin/dubois); use WebDB; my ($dbh, $sth, $count, $user); # DECLARE VARIABLES $dbh = WebDB::connect_with_option_file();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: connect_with_option_file
by graff (Chancellor) on Jul 26, 2005 at 01:21 UTC | |
by gmacfadden (Sexton) on Jul 27, 2005 at 01:10 UTC | |
by graff (Chancellor) on Jul 27, 2005 at 14:53 UTC | |
by gmacfadden (Sexton) on Jul 28, 2005 at 00:59 UTC | |
|
Re: connect_with_option_file
by salva (Canon) on Jul 27, 2005 at 15:31 UTC |