cleaned up mysql statements
git-svn-id: http://yolanda.mister-muffin.de/svn@20 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
a1bf6a20c2
commit
ccd3c6ab07
5 changed files with 31 additions and 25 deletions
|
@ -8,5 +8,4 @@ fill with some data:
|
||||||
eg.: insert into tagcloud values ('web tv', 68);
|
eg.: insert into tagcloud values ('web tv', 68);
|
||||||
|
|
||||||
create table users (id int auto_increment not null, username varchar(255) not null, password char(41) not null, primary key (id));
|
create table users (id int auto_increment not null, username varchar(255) not null, password char(41) not null, primary key (id));
|
||||||
|
|
||||||
insert into users (username, password) values ('user', password('pass'));
|
insert into users (username, password) values ('user', password('pass'));
|
||||||
|
|
|
@ -3,13 +3,13 @@ require "/var/www/perl/include.pl";
|
||||||
#get tags from database and fill $page with xml
|
#get tags from database and fill $page with xml
|
||||||
sub fill_tagcloud {
|
sub fill_tagcloud {
|
||||||
#connect to db
|
#connect to db
|
||||||
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#prepare query
|
#prepare query
|
||||||
my $sth = $dbh->prepare(qq{select text, count from tagcloud });
|
my $sth = $dbh->prepare(qq{select text, count from tagcloud }) or die $dbh->errstr;
|
||||||
|
|
||||||
#execute it
|
#execute it
|
||||||
$sth->execute();
|
$sth->execute() or die $dbh->errstr;
|
||||||
|
|
||||||
#get every returned value
|
#get every returned value
|
||||||
while (my ($text, $count) = $sth->fetchrow_array())
|
while (my ($text, $count) = $sth->fetchrow_array())
|
||||||
|
@ -19,10 +19,10 @@ sub fill_tagcloud {
|
||||||
}
|
}
|
||||||
|
|
||||||
#finish query
|
#finish query
|
||||||
$sth->finish();
|
$sth->finish() or die $dbh->errstr;
|
||||||
|
|
||||||
#close db
|
#close db
|
||||||
$dbh->disconnect();
|
$dbh->disconnect() or die $dbh->errstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#return a username from passed session id
|
#return a username from passed session id
|
||||||
|
@ -31,23 +31,23 @@ sub get_username_from_sid {
|
||||||
my ($sid) = @_;
|
my ($sid) = @_;
|
||||||
|
|
||||||
#connect to db
|
#connect to db
|
||||||
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#prepare query
|
#prepare query
|
||||||
my $sth = $dbh->prepare(qq{select username from users where sid = '$sid'});
|
my $sth = $dbh->prepare(qq{select username from users where sid = '$sid'}) or die $dbh->errstr;
|
||||||
|
|
||||||
#execute it
|
#execute it
|
||||||
$sth->execute();
|
$sth->execute() or die $dbh->errstr;
|
||||||
|
|
||||||
#save the resulting username
|
#save the resulting username
|
||||||
my ($username) = $sth->fetchrow_array();
|
my ($username) = $sth->fetchrow_array() or die $dbh->errstr;
|
||||||
|
|
||||||
#finish query
|
#finish query
|
||||||
$sth->finish();
|
$sth->finish() or die $dbh->errstr;
|
||||||
|
|
||||||
#close db
|
#close db
|
||||||
$dbh->disconnect();
|
$dbh->disconnect() or die $dbh->errstr;
|
||||||
|
|
||||||
#return username
|
#return
|
||||||
return $username;
|
return $username;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,4 @@ $dbhost = 'localhost';
|
||||||
$dbuser = 'root';
|
$dbuser = 'root';
|
||||||
$dbpass = '';
|
$dbpass = '';
|
||||||
$session_name = 'sid';
|
$session_name = 'sid';
|
||||||
$cwd = $ENV{PWD};
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -8,23 +8,17 @@ $session = new CGI::Session;
|
||||||
#if username and password are passed put them into the database
|
#if username and password are passed put them into the database
|
||||||
if($query->param('user') and $query->param('pass')) {
|
if($query->param('user') and $query->param('pass')) {
|
||||||
#connect to db
|
#connect to db
|
||||||
$dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass);
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#save POST data in local variables
|
#save POST data in local variables
|
||||||
my $user = $query->param("user");
|
my $user = $query->param("user");
|
||||||
my $pass = $query->param("pass");
|
my $pass = $query->param("pass");
|
||||||
|
|
||||||
#prepare query
|
#do query
|
||||||
$sth = $dbh->prepare(qq{insert into users (username, password) values ('$user', password('$pass'))});
|
$dbh->do(qq{insert into users (username, password) values ('$user', password('$pass'))}) or die $dbh->errstr;
|
||||||
|
|
||||||
#execute query
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
#finish query
|
|
||||||
$sth->finish();
|
|
||||||
|
|
||||||
#disconnect db
|
#disconnect db
|
||||||
$dbh->disconnect();
|
$dbh->disconnect() or die $dbh->errstr;
|
||||||
|
|
||||||
#print a little confirmation
|
#print a little confirmation
|
||||||
print $session->header();
|
print $session->header();
|
||||||
|
|
|
@ -8,6 +8,7 @@ $session = new CGI::Session;
|
||||||
sub hook {
|
sub hook {
|
||||||
#this is going to become an ajax progress bar
|
#this is going to become an ajax progress bar
|
||||||
my ($filename, $buffer, $bytes_read, $data) = @_;
|
my ($filename, $buffer, $bytes_read, $data) = @_;
|
||||||
|
print $ENV{'CONTENT_LENGTH'};
|
||||||
print sha256_hex($buffer);
|
print sha256_hex($buffer);
|
||||||
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
||||||
print "Read $bytes_read bytes of $filename\n";
|
print "Read $bytes_read bytes of $filename\n";
|
||||||
|
@ -17,6 +18,15 @@ sub hook {
|
||||||
my $username = get_username_from_sid($session->id);
|
my $username = get_username_from_sid($session->id);
|
||||||
|
|
||||||
if($username) {
|
if($username) {
|
||||||
|
#connect to db
|
||||||
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
|
#save POST data in local variables
|
||||||
|
my $title = $query->param("title");
|
||||||
|
|
||||||
|
#do query
|
||||||
|
$dbh->do(qq{insert into videos (title, username) values ('$title', '$username')}) or die $dbh->errstr;
|
||||||
|
|
||||||
my $filename = $query->param("file");
|
my $filename = $query->param("file");
|
||||||
my $title = $query->param("title");
|
my $title = $query->param("title");
|
||||||
$upload_filehandle = $query->upload("file");
|
$upload_filehandle = $query->upload("file");
|
||||||
|
@ -25,6 +35,10 @@ if($username) {
|
||||||
{
|
{
|
||||||
print;
|
print;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#disconnect db
|
||||||
|
$dbh->disconnect() or die $dbh->errstr;
|
||||||
} else {
|
} else {
|
||||||
print $session->header();
|
print $session->header();
|
||||||
print "nope...";
|
print "nope...";
|
||||||
|
|
Loading…
Reference in a new issue