in reply to dbi question

...but $dbh is not dbi, which has prepare().

Not sure what you mean.  connect returns a database handle object (typically stored in a variable named $dbh) which does have the method prepare (see Database Handle Methods).  In other words, writing $dbh->prepare(...) is perfectly fine.