Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The script below prints at the bottom and this ALWAYS shows the real order of posts, but somehow it becomes distorted in my mysql database. After 4 attempts, I've noticed the mysql setup always appears in the same wrong order, so it's not randomly throwing things in there. Anyone know what might be the problem?
#!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use DB_File; use DBI; my $add; my %chat; my $chat = "chat.db"; tie %chat, "DB_File", "$chat", O_CREAT|O_RDWR, 0644, $DB_BTREE or die "Cannot open file 'chat': $!\n"; my $dbase = "*"; my $mysql_user = "*"; my $mysql_pass = "*"; print header, start_html(); ### # connect to database ### my $dbh = DBI->connect("DBI:mysql:$dbase", $mysql_user, $mysql_pass) o +r print DBI->errstr; foreach my $key (reverse sort keys %chat) { my ( $name, $message, $userip) = split /~~/, $chat{$key}; my $data = qq(INSERT INTO chat (name, message, mood, ip, posttime) VAL +UES(?,?,?,?,?)); my $sth = $dbh->prepare($data); $sth->execute($name, $message, "happy", $userip, "0:0:0") or die $dbh- +>errstr; print qq($name $message $userip<br><br>); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: database not in correct order
by dragonchild (Archbishop) on Nov 27, 2007 at 02:46 UTC | |
|
Re: database not in correct order
by Herkum (Parson) on Nov 27, 2007 at 03:51 UTC | |
by aquarium (Curate) on Nov 27, 2007 at 05:04 UTC | |
by CountZero (Bishop) on Nov 27, 2007 at 15:24 UTC | |
|
Re: database not in correct order
by graff (Chancellor) on Nov 27, 2007 at 03:34 UTC | |
|
Re: database not in correct order
by tuxz0r (Pilgrim) on Nov 27, 2007 at 02:42 UTC | |
by Anonymous Monk on Nov 27, 2007 at 03:03 UTC | |
by dws (Chancellor) on Nov 27, 2007 at 05:42 UTC |