in reply to Re: MySQL count with DBI
in thread MySQL count with DBI
Not to be a pita, but I think it is vastly clearer and safer to explicitly write SQLs explicitly into a variable, rather than read them from STDIN. In addition, I'm not a huge fan of using ->fetchrow_array() to get back a single method: that is exactly what ->selectrow_array() is meant for, I think. Finally, if the questioner is just starting to use DBI he should probably enable it's error-handling apparatus explicitly until he knows when/why he might not want to use it. Similarly, I would explicitly turn off autocommit to limit accidental damage to the DB.
No major changes there, smitz, but just seems "safer" this way to me....
-Tatsmy $dbh = DBI->connect('DBI:mysql:my_db', 'user', 'pass', {RaiseError +=> 1, PrintError => 1, AutoCommit => 0}) or die "Error connecting to +DB: $DBI::errstr\n"; my $sql = "SELECT COUNT(*) FROM music"; my @row = $dbh->selectrow_array($sql); print "Found $row[0] results\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: MySQL count with DBI
by smitz (Chaplain) on May 09, 2003 at 15:33 UTC | |
by Itatsumaki (Friar) on May 09, 2003 at 16:45 UTC |
In Section
Seekers of Perl Wisdom