DBI stuff
Stephen Judd
StephenJ at web.co.nz
Wed Aug 21 20:37:51 CDT 2002
> use DBI;
>
> my $dbh =
> DBI->connect("DBI:mysql:database=db_name;host=hostname.co.nz",
> $dbusername,
> $dbpassword);
>
> how would I connect to a mSQL db and would i need any other modules?
I think the one you're using for MySQL will work. MySQL is supposed to be compatible with mSQL at a binary level.
If you're going to do more with DBI, invest in this:
http://www.oreilly.com/catalog/perldbi/
Well worth it. Dymocks or Capital Books probably have a copy in stock.
> or how about this one:
>
> I need to run 3 bits of sql on a mySQL db would this work?
>
>
> my $SQL1 = '';
> my $SQL2 = '';
> my $SQL3 = '';
> my @queries = ($SQL1, $SQL2, $SQL3);
> my $dbh =
> DBI->connect("DBI:mysql:database=bd_name;host=hostname.co.nz",
> $dbusername,
> $dbpassword);
> foreach my $query (@queries) {
> my $sth = $dbh->prepare($query);
> $sth->execute();
> $sth->finish();
> }
> $dbh->disconnect();
Yes, that should work Just Fine. It's been a while, but I think you can reuse your statement handle too:
my $sth;
foreach my $query (@queries) {
$sth = $dbh->prepare($query);
$sth->execute();
}
$sth->finish();
which might speed things up in a nested loop more than somewhat.
Stephen
More information about the Wellington-pm
mailing list