LPM: DBI woes

Wesley wsheldahl at qx.net
Thu Feb 24 18:15:54 CST 2000


> >         So in a nutshell, I would try changing that one line to:
> >         $day = $sth->fetch;
> 
> I'm confused on this one. Now $day is an array reference, right? Do you
> use this in actual code? That is, is $day actually a field from the
> database. Does the method do some sort of wantarray in there, and intuit
> what you want?

Uh, best answer to that is OOPS!  Please ignore that one-liner change. 
:-)
 
> > as long as you're sure it will always return a record and don't have to
> > test for that possibility.  I would also use $dbh->prepare_cached as
> > David suggested because I think the most recent DBI docs recommend it,
> > though I don't think that will affect your problem one way or the
> > other.  OTOH it might!  :-)
> 
> Yeah. I did not quite understand the difference between prepare and
> prepare_cached. It seems that the only difference is that if you re-call
> the statement handle with the same arguments, it does not actually
> contact the database, but just returns the value it got last time. While
> I can certainly see that there are situations where this would be
> useful, this is not one of them. Now that I am aware of it, I can see
> other places where I'd like to use it, though.

Yes, prepare_cached returns the same statement handle.  Mind you, this
is not necessarily the same as the same value from the query, just the
same statement handle.  For databases like SQL Server or Oracle, I think
this would be more of a gain, since preparing a statement is a distinct
step that might be able to be saved or speeded up with this method.  May
not help much with Access though.
 
> >         Another option would be to bind the column ahead of time, just for the
> > sake of doing it differently.  I think this would look something like:
> >
> > $sth = $dbh->prepare_cached($sql);
> > $sth->bind_col(\$day);
> > foreach $ID (@conflicts)
> >         $sth->execute($ID);
> >         $sth->fetch;
> >         print "$day\n";
> > }
> > only with proper syntax etc.
> 
> Nope, can't do that. You have to execute before you can bind_columns.
> Darn.

Darn it.  I knew you had to do something before bind_col, I was hoping
prepare was all.  Hmmm, seems the docs say that whether you have to
execute first depends on the driver.
 
Looks like my DBI is rusting fast.

-- 
Wes Sheldahl
wsheldahl at qx.net



More information about the Lexington-pm mailing list