#-------------------------------------------------------------
# dbtool.pl
#
# Автор: Нифонтов Евгений
#
# Процедуры работы с БД mSQL для статистики входов в WWW-сервер
#
#--------------------------------------------------------------
use Msql;
sub CountVisit{
$table="countvisits";
if ($dbh = Msql->Connect){
} else {
die "not ok 1: $Msql::db_errstr\n";
}
if ($dbh->SelectDB("wwwstat")){
} else {
die "not ok 2: $Msql::db_errstr
Please make sure that a database \"index\" exists
and that you can read and write on it
";
}
local($script)=$ENV{'SCRIPT_NAME'};
$sth = $dbh->Query("select nvisits from $table where script_name=\'$script\'") or die $Msql::db_errstr;
if(local($count)=$sth->FetchRow){
$count++;
$dbh->Query("update $table set nvisits=$count where script_name=\'$script\'")or die $Msql::db_errstr;
return $count;
}
else{
$dbh->Query("insert into $table values (\'$script\',1)") or die $Msql::db_errstr;
return 1;
}
} # sub CountVisit
# End of Lib