if (&IsParam("useStrict")) { use strict; }
sub openDB {
- my $dsn = "DBI:mysql:$param{'DBName'}:$param{'SQLHost'}";
- $dbh = DBI->connect($dsn, $param{'SQLUser'}, $param{'SQLPass'});
+ my ($db, $user, $pass) = @_;
+ my $dsn = "DBI:mysql:$db:$param{'SQLHost'}";
+ $dbh = DBI->connect($dsn, $user, $pass);
if ($dbh) {
&status("Opened MySQL connection to $param{'SQLHost'}");
return;
}
+ &SQLDebug($query);
if (!$sth->execute) {
&ERROR("Get => '$query'");
&ERROR("Get => $DBI::errstr");
+ &SQLDebug($DBI::errstr);
return;
}
my %retval;
my $sth = $dbh->prepare($query);
- &ERROR("GetCol => '$query'") unless $sth->execute;
+ &SQLDebug($query);
+ if (!$sth->execute) {
+ &ERROR("GetCol => '$query'");
+ &SQLDebug($DBI::errstr);
+ }
if (defined $type and $type == 1) {
while (my @row = $sth->fetchrow_array) {
return 0;
}
+ &SQLDebug($query);
if (!$sth->execute) {
&ERROR("Raw($prefix): => '$query'");
&ERROR("Raw($prefix): $DBI::errstr");
+ &SQLDebug($DBI::errstr);
return 0;
}
my @retval;
my $sth = $dbh->prepare($query);
+ &SQLDebug($query);
&ERROR("RawReturn => '$query'.") unless $sth->execute;
while (my @row = $sth->fetchrow_array) {
push(@retval, $row[0]);
my $query = "SELECT $primkey FROM $table";
my $sth = $dbh->prepare($query);
- $sth->execute;
+ &SQLDebug($query);
+ &WARN("ERROR: getKeys($query)") unless $sth->execute;
+
while (my @row = $sth->fetchrow_array) {
push(@retval, $row[0]);
}
my $query = "SELECT $select FROM $table LIMIT $rand,1";
my $sth = $dbh->prepare($query);
- $sth->execute;
+ &SQLDebug($query);
+ &WARN("randKey($query)") unless $sth->execute;
my @retval = $sth->fetchrow_array;
$sth->finish;
my $query = "SELECT $select FROM $table WHERE $key LIKE ".
&dbQuote($str);
my $sth = $dbh->prepare($query);
- $sth->execute;
+ &SQLDebug($query);
+ &WARN("Search($query)") unless $sth->execute;
while (my @row = $sth->fetchrow_array) {
push(@results, $row[0]);
return 1;
}
+sub SQLDebug {
+ return unless (&IsParam("SQLDebug"));
+
+ print SQLDEBUG $_[0]."\n";
+}
+
1;