in reply to Re: accessing Apache::DBI 'cached connections'
in thread accessing Apache::DBI 'cached connections'

well, i removed the double-load of DBI ...

i should get *some* output from Data::Dumper if i've connected. another script on the same server ( non-mod_perl ) give me:

$VAR1 = bless( {}, 'DBI::db' );
so i'm lost ...

Replies are listed 'Best First'.
Re: Re: Re: accessing Apache::DBI 'cached connections'
by cees (Curate) on Jul 21, 2003 at 22:15 UTC

    Apache::DBI works transparently, so if one scripts works, and the other doesn't, then there must be differences in the way you connect in the two scripts. In other words a script that works without Apache::DBI must also work with Apache::DBI!

    Try the following bit of code and see what you get...

    #!/usr/bin/perl use CGI qw/:standard/; use DBI; use Data::Dumper; $Apache::DBI::DEBUG = 2; # Turn on Apache::DBI debugging print header, start_html('Testing Apache::DBI'), h1('Testing Apache::DBI'); my $dbh; eval { $dbh = DBI->connect( "DBI:mysql:database=test;host=localhost", undef +, undef, { RaiseError => 1 } ) ; }; if ($@) { print p('DBI Error: '.$@); } else { print p('Connect success'); print p("We are using Apache::DBI") if $dbh->isa('Apache::DBI::db'); print pre(Dumper($dbh)); } print end_html();

    When I call that with Apache::DBI enabled, I get the following:

    Testing Apache::DBI
    
    Connect success
    
    We are using Apache::DBI
    
    $VAR1 = bless( {}, 'Apache::DBI::db' );
    

    And in my error log I get:

    13692 Apache::DBI need ping: yes
    13692 Apache::DBI new connect to 'database=test;host=localhostAutoCommit=1PrintError=1RaiseError=1'
    

    Cheers,

    Cees

    Update: Looks like this got solved while I was writing my test script. I guess I'll have to be quicker next time...

Re: Re: Re: accessing Apache::DBI 'cached connections'
by perrin (Chancellor) on Jul 21, 2003 at 21:27 UTC
    In your example, $DBH is just an empty lexical variable that you declared right before dumping it. The DBI->connect code will never even run because "my $DBH" will always return true. (It returns the result of the my() call, not the value of the variable.)

    UPDATE: Advice about the return value of my() is not correct. See below.

      Your post sounded so good, I  ++'d it, but it's wrong.

      #!/usr/bin/perl -w my $DBH ||= retval('1'); print "$DBH\n"; sub retval { return $_[0] }

      This prints '1'.

      Update: Oddly enough, Camel 3 calls 'my' a named unary operator and lists named unary operators at higher precedence than any of assignment, assignment operators or logical operators, so you should be right, but the code doesn't work that way for me, at least not on 5.8.0 or 5.005_03.

      Newer Update: 'my' probably does have higher precedence thatn ||=, but it doesn't matter because it returns false.

      my $orr || print "or\n"; my $andd && print "and\n";

      prints 'or'.

      --Bob Niederman, http://bob-n.com
        You're right, the DBI->connect part will get executed. However, since he has || and not ||=, it will just get thrown away.
Re: Re: Re: accessing Apache::DBI 'cached connections'
by bobn (Chaplain) on Jul 21, 2003 at 21:27 UTC

    Did you also fix the module code so that you are actually assigning the return value of DBI->connect to $DBH?

    --Bob Niederman, http://bob-n.com
      i had the connect string completely wrong.

      it's fixed now, and reads:

      $DBH = DBI->connect( "dbi:mysql:rentsavers", "root", "", ) ;
      i can't believe i blew the $dsn ....
        This is why you have to check return values or turn on RaiseError.
      yes, i changed it to:
      $DBH = DBI->connect( "dbi:mysql:localhost", "rentsavers", "root", "", +) ;
      but i still get nothing ....