从数据库删除数据

时间:2013-07-29 12:48:33

标签: perl cgi

我正在尝试从数据库中删除一些数据。但它向我显示以下错误:

Unmatched right curly bracket at C:/wamp/bin/apache/apache2.2.22/cgi-bin/ova/db.pl line 13, at end of line\r
Missing $ on loop variable at C:/wamp/bin/apache/apache2.2.22/cgi-bin/ova/db.pl line 28.\r

代码:

package DBM;
use DBI;
use POSIX 'fmod';

#variabel globale qe formon connection string
our $rConn = {
    database => 'people',
    user     => 'root',
    pass     => '',
    host     => '127.0.0.1' 
};

#variabel global qe percakton rdbms qe do te perdoret (ex.mysql,postgres etj)
our $rdbms = "mysql";

#variabel global qe percakton handle per te kryer lidhjen me Databazen
our $dbh   = undef;

sub connection {
    $dbh = DBI->connect("DBI:$rdbms:".$rConn->{database}.":". $rConn->{host}, $rConn->{user}, $rConn->{pass});
    return ($dbh);
};


sub do_delete {
    my $rData = @_;
    my $rCondition = $rData->{condition};
    my $cWhere = " WHERE 1=1 ";
    my $i=0;
    foreach my ($key,$value)($rCondition){

        if (scalar($value)>1){
            $cWhere .= " AND ". $key;
            my $counter=0;
            foreach my $cValueArray ($value){
                if(fmod($counter,3)==0) {
                    $cWhere.=" ".$key." ".$cValueArray." ";
                }
                else {
                    $cWhere.= " ".$value. " ";
                }
            }
        }
        else{
            $cWhere .= " AND ". $key."=". $value;
        }
    }

    my $queryDelete = "DELETE FROM $rData->{table} $cWhere";
    return ($queryDelete);
    my $dbh = connection;  
    $dbh->prepare($queryDelete) or die "Can't prepare $queryDelete: $dbh->errstr\n";
    return ($sqlDelete->execute);
}
1;

我看不出那个问题在哪里。

1 个答案:

答案 0 :(得分:0)

不确定第一个错误,但

foreach my ($key, $value) ($rCondition) {

看起来很奇怪。只能有一个循环变量,而不是一对。