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);
|
||||
|
||||
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'));
|
||||
|
|
|
@ -3,13 +3,13 @@ require "/var/www/perl/include.pl";
|
|||
#get tags from database and fill $page with xml
|
||||
sub fill_tagcloud {
|
||||
#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
|
||||
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
|
||||
$sth->execute();
|
||||
$sth->execute() or die $dbh->errstr;
|
||||
|
||||
#get every returned value
|
||||
while (my ($text, $count) = $sth->fetchrow_array())
|
||||
|
@ -19,10 +19,10 @@ sub fill_tagcloud {
|
|||
}
|
||||
|
||||
#finish query
|
||||
$sth->finish();
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
#close db
|
||||
$dbh->disconnect();
|
||||
$dbh->disconnect() or die $dbh->errstr;
|
||||
}
|
||||
|
||||
#return a username from passed session id
|
||||
|
@ -31,23 +31,23 @@ sub get_username_from_sid {
|
|||
my ($sid) = @_;
|
||||
|
||||
#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
|
||||
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
|
||||
$sth->execute();
|
||||
$sth->execute() or die $dbh->errstr;
|
||||
|
||||
#save the resulting username
|
||||
my ($username) = $sth->fetchrow_array();
|
||||
my ($username) = $sth->fetchrow_array() or die $dbh->errstr;
|
||||
|
||||
#finish query
|
||||
$sth->finish();
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
#close db
|
||||
$dbh->disconnect();
|
||||
$dbh->disconnect() or die $dbh->errstr;
|
||||
|
||||
#return username
|
||||
#return
|
||||
return $username;
|
||||
}
|
||||
|
|
|
@ -10,5 +10,4 @@ $dbhost = 'localhost';
|
|||
$dbuser = 'root';
|
||||
$dbpass = '';
|
||||
$session_name = 'sid';
|
||||
$cwd = $ENV{PWD};
|
||||
1;
|
||||
|
|
|
@ -8,23 +8,17 @@ $session = new CGI::Session;
|
|||
#if username and password are passed put them into the database
|
||||
if($query->param('user') and $query->param('pass')) {
|
||||
#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
|
||||
my $user = $query->param("user");
|
||||
my $pass = $query->param("pass");
|
||||
|
||||
#prepare query
|
||||
$sth = $dbh->prepare(qq{insert into users (username, password) values ('$user', password('$pass'))});
|
||||
|
||||
#execute query
|
||||
$sth->execute();
|
||||
|
||||
#finish query
|
||||
$sth->finish();
|
||||
#do query
|
||||
$dbh->do(qq{insert into users (username, password) values ('$user', password('$pass'))}) or die $dbh->errstr;
|
||||
|
||||
#disconnect db
|
||||
$dbh->disconnect();
|
||||
$dbh->disconnect() or die $dbh->errstr;
|
||||
|
||||
#print a little confirmation
|
||||
print $session->header();
|
||||
|
|
|
@ -8,6 +8,7 @@ $session = new CGI::Session;
|
|||
sub hook {
|
||||
#this is going to become an ajax progress bar
|
||||
my ($filename, $buffer, $bytes_read, $data) = @_;
|
||||
print $ENV{'CONTENT_LENGTH'};
|
||||
print sha256_hex($buffer);
|
||||
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
||||
print "Read $bytes_read bytes of $filename\n";
|
||||
|
@ -17,6 +18,15 @@ sub hook {
|
|||
my $username = get_username_from_sid($session->id);
|
||||
|
||||
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 $title = $query->param("title");
|
||||
$upload_filehandle = $query->upload("file");
|
||||
|
@ -25,6 +35,10 @@ if($username) {
|
|||
{
|
||||
print;
|
||||
}
|
||||
|
||||
|
||||
#disconnect db
|
||||
$dbh->disconnect() or die $dbh->errstr;
|
||||
} else {
|
||||
print $session->header();
|
||||
print "nope...";
|
||||
|
|
Loading…
Reference in a new issue