summaryrefslogtreecommitdiffstats
path: root/modules/mysql.pl
diff options
context:
space:
mode:
authorLibravatarWilliam Heimbigner <william.heimbigner@gmail.com>2007-06-28 23:48:48 +0000
committerLibravatarWilliam Heimbigner <william.heimbigner@gmail.com>2007-06-28 23:48:48 +0000
commit6907da0a5da3d45a91c3ac4893e5b890200b27eb (patch)
tree5a61df15a30b6d0aefa6c6e72e7eab2d8f03de1f /modules/mysql.pl
parent638d9eae9e63755e26f9843985597e6f1c7c5f8e (diff)
modularized stuff, fixed alert logic, simplified stuff, updated TODO
Diffstat (limited to 'modules/mysql.pl')
-rw-r--r--modules/mysql.pl49
1 files changed, 33 insertions, 16 deletions
diff --git a/modules/mysql.pl b/modules/mysql.pl
index 463dbaf..2f96410 100644
--- a/modules/mysql.pl
+++ b/modules/mysql.pl
@@ -1,30 +1,47 @@
+package ASM::DB;
+
use warnings;
use strict;
use DBI;
-sub sql_connect
-{
- $::dbh = DBI->connect("DBI:mysql:database=$::mysql->{db};host=$::mysql->{host};port=$::mysql->{port}",
- $::mysql->{user}, $::mysql->{pass});
- $::dbh->{mysql_auto_reconnect} = 1;
+sub new {
+ my $module = shift;
+ my ($db, $host, $port, $user, $pass, $table) = @_;
+ my $self = {};
+ $self->{DBH} = DBI->connect("DBI:mysql:database=$db;host=$host;port=$port", $user, $pass);
+ $self->{DBH}->{mysql_auto_reconnect} = 1;
+ $self->{TABLE} = $table;
+ bless($self);
+ return $self;
}
-sub sql_record
+#sub sql_connect
+#{
+# $::dbh = DBI->connect("DBI:mysql:database=$::mysql->{db};host=$::mysql->{host};port=$::mysql->{port}",
+# $::mysql->{user}, $::mysql->{pass});
+# $::dbh->{mysql_auto_reconnect} = 1;
+#}
+
+sub record
{
+ my $self = shift;
my ($channel, $nick, $user, $host, $gecos, $level, $id, $reason) = @_;
- $::dbh->do("INSERT INTO $::mysql->{table} (channel, nick, user, host, gecos, level, id, reason) VALUES (" .
- $::dbh->quote($channel) . ", " . $::dbh->quote($nick) . ", " . $::dbh->quote($user) .
- ", " . $::dbh->quote($host) . ", " . $::dbh->quote($gecos) . ", " . $::dbh->quote($level) . ", " .
- $::dbh->quote($id) . ", " . $::dbh->quote($reason) . ");");
+ my $dbh = $self->{DBH};
+ $dbh->do("INSERT INTO $self->{TABLE} (channel, nick, user, host, gecos, level, id, reason) VALUES (" .
+ $dbh->quote($channel) . ", " . $dbh->quote($nick) . ", " . $dbh->quote($user) .
+ ", " . $dbh->quote($host) . ", " . $dbh->quote($gecos) . ", " . $dbh->quote($level) . ", " .
+ $dbh->quote($id) . ", " . $dbh->quote($reason) . ");");
}
-sub sql_query
+sub query
{
+ my $self = shift;
my ($channel, $nick, $user, $host) = @_;
- $channel = $::dbh->quote($channel);
- $nick = $::dbh->quote($nick);
- $user = $::dbh->quote($user);
- $host = $::dbh->quote($host);
+ my $dbh = $self->{DBH};
+ $channel = $dbh->quote($channel);
+ $nick = $dbh->quote($nick);
+ $user = $dbh->quote($user);
+ $host = $dbh->quote($host);
$nick =~ s/\*/%/g;
$nick =~ s/_/\\_/g;
@@ -37,7 +54,7 @@ sub sql_query
$host =~ s/\*/%/g;
$host =~ s/_/\\_/g;
$host =~ s/\?/_/g;
- my $sth = $::dbh->prepare("SELECT * from $::mysql->{table} WHERE channel = $channel and nick like $nick and user like $user and host like $host;");
+ my $sth = $dbh->prepare("SELECT * from $self->{TABLE} WHERE channel = $channel and nick like $nick and user like $user and host like $host;");
$sth->execute;
my $i = 0;
while (my $ref = $sth->fetchrow_arrayref) {