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

I have finally managed to install DBD::mysql (with the help of previous postings) but am still not 100% sure about its success.

I installed using 'make install' instead of 'make && make test' and finally it seemed to work. After running my dbd script I got the following results so I assume that the driver has been installed?:
Driver: ExampleP Data Source is dbi:ExampleP:dir=. Driver: Proxy Driver: mysql
When I attempt to run my DBD test script (I should also add that I have had this run succesfully many times on different systems) it falls over on the 'connect' line. This is my code
#!/usr/bin/perl use strict; use DBI; BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } my $dbh = DBI->connect('DBI:mysql:wwf', 'username', 'pass') || die "c +ant open db"; my $sql = "SELECT * FROM url WHERE rec_id = 1399863634"; my $sth = $dbh->prepare( $sql ); $sth->execute(); my $goodrow = $sth->fetchrow_hashref; $dbh->disconnect(); print "$goodrow->{'url'}";
Please note that I am %100 sure of my database detail (ie username pass etc). Even if the database details were wrong, the die command should at least give me the error.

Does anyone have any suggestions or further tests for me to use?

Thanks
Costas

Replies are listed 'Best First'.
Re: DBD::mysql
by ralphie (Friar) on Oct 17, 2001 at 17:05 UTC
    sounds like you haven't turned on the dbi trace log ... i'd suggest that in a situation like this...
    e.g.,
    unlink 'dbitrace.log' if -e 'dbitrace.log'; DBI->trace(2,'dbitrace.log');
Re: DBD::mysql
by MZSanford (Curate) on Oct 17, 2001 at 14:53 UTC
    What do you mean by "falls over" ? If you would not mind, change your die message to
    <code lang="perl">die "cant open db : $DBI::errstr\n"</code>
    If you re-run, and post the error message we can see if the problem is in loading the module (as it was during make test), or in connecting (since you are unsure on the <code lang="perl">connect()</code> details).
    i had a memory leak once, and it ruined my favorite shirt.
      I do not get any feedback of any kind. The die error is not even triggered.

      The program runs fine until it gets to this line and then just stops. Anything past the connect line is not executed and I am given no feedback from the connect line whatsoever.

      I am wrong in saying that if the db details were wrong then the die command would be executed?

      any further ideas?
        Are you running this from the command line or a browser ?

        1. Browser : run it from the command line. If you are calling <code lang="perl">die()</code> before you print a header, the prowser would print nothing.
        2. Command line : It appears that there is still something wrong with a path setup somewhere, and the mysql.so file is not getting loaded. It usually will not go into a black hole like that (it usually prints a cannot load message like make test did), but i have seen DBD::Sybase do this on rare occasion. So, back to the path issue from your other posts

        i had a memory leak once, and it ruined my favorite shirt.
Re: DBD::mysql
by kostis (Initiate) on Oct 17, 2001 at 16:51 UTC
    Costa, I don't know what the source of the problem might be but may I recommend DBI's method "ping" after the connect to see if the connection is alive? This basically does a "SELECT 1" on the connection you call it on and is generally a good way of testing since it less likely to fail due to, say, permissioning issues on the database that would prevent data from being returned even though they are there. e.g.
    unless ($dbh->ping()) { print STDERR "Oops, we definitely have a problem\n"; }
    Regards...
Re: DBD::mysql
by busunsl (Vicar) on Oct 17, 2001 at 14:53 UTC
    You say 'it falls over the connect line'.

    What does that mean? Does it die, saying "cant open db"?
    In this case you should provide more information in your die string, like die "cant open db: " . $DBI::errstr . "\n";
    This would give you the error comming from the database.

    You can also use the printerror and raiseerror flags, take a look at perldoc DBI for that.

    update: fixed bug

Re: DBD::mysql
by barndoor (Pilgrim) on Oct 17, 2001 at 19:42 UTC
    Are you sure the connect is failing?

    Does the column 'url' exist in the url table? Does the select return a row?

    If not the print will not print anything. (Use warnings to check for this).

    Hope this helps.
      I can tell you these facts for definite.

      After extensive testing

      1)the mysql DBD driver is being found. (If i try looking for myslx DBD for example I get a proper 'cant find DBD' error.

      2)It is not finding any of the datbases within mysql.

      I know this because I have tried a standard DBD query script which i have used before and that usaually lists db names (this time it does not). Also if i try to connect to a non existant db name I still get zero feedback (Internal Server Error withouth printing a header)

      It must be a bad installation. costas