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

hi every1,
i don't know why this code doesn't produce any error. this is the first time i'm using a mysql db on a shared computer. basically this code does not give me a error...i don't know how else to debug this.

the below code only prints "hey". It stops after that?? I can't get it to print a error and it doesn't print "hi".

Even if i SWITCH "or print" with "or die", it seems to die but w/out no error. whats wrong with this? i also installed the latest version of DBI for ActiveState too.

sub dbi_test { use DBI; print "hey"; my $dbh_r = DBI->connect('DBI:mysql:mydb_name:host=pctwo') or print "C +ouldn't connect to database: " . DBI->errstr; print "hi"; }
Any ideas on what I can do to see what the problem is here?

thanks!

Replies are listed 'Best First'.
Re: How come no DBI error??
by moot (Chaplain) on Apr 16, 2005 at 06:07 UTC
    Assume your database is setup in a state where you would expect connections to fail, you might be suffering from buffering - your prints have no newlines at the end so the messages are sitting in a buffer waiting to be output. Try adding newlines or setting $| to a positive integer, and see what results you get.
      hey!

      okay when I tried adding $! = 1; it started to print out error statements...then i realized my problem was i didn't install a mysql driver for dbi. then once i did, it was fine...but then I deleted the $! = 1; and it still prints error and works fine?

      Should I leave the $! = 1; in the script or does it not matter now?
      thanks
        Are you adding $|=1 or $!=1 ? Setting $! is actually setting an error code. $|=1 is what was suggested--what that does (see perlvar man page) is set it to autoflush any output, so you're assured it goes to the screen immediately. otherwise, you could potentially have code like (i've had this happen in c way more than in perl) this, but you never see "hi":
        do_stuff(); print "hi"; do_something_that_fatally_errors();
        What errors do you get and the script still works fine?

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: How come no DBI error??
by Anonymous Monk on Apr 16, 2005 at 19:38 UTC

    Use strict and warnings, and the error will show up.