Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am currently trying to create a prompt for a perl script to have the user enter their MySQL username and password before executing the code. That part is easy enough but what I want it to do is loop if the DBI returns an accessed denied error thus asking the user to reinput the information. Any suggestions would be greatly appreciated. Here is the begging part of the code

my $database = ""; my $platform = "mysql"; my $host = "5.214.214.121"; my $port = "3306"; print "Enter User Name\n"; my $user = <>; chomp $user; print "Enter Password\n"; my $pw = <>; chomp $pw; $dsn = "dbi:mysql:$database:5.214.214.121:3306"; $dbh = DBI->connect($dsn, $user, $pw, { RaiseError => 0, Print +Error => 1 });

Replies are listed 'Best First'.
Re: DBI user input question
by Anonymous Monk on May 14, 2012 at 20:00 UTC

      Still doesn't help me. What it does is disconnects and terminates the script upon error. Is there even a way to prompt the user to enter the credentials again without having to re-execute the program?

        Please show a short but complete program (with the user credentials elided!) that replicates the problem. Also show us the error message you get and the behaviour you expect. This helps us help you better, because we can then diagnose what error happens and maybe reproduce your situation.

        The DBI documentation says that ->connect returns undef on failure, so your error must be somewhere else.