0

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

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;

我看不出问题出在哪里。

4

1 回答 1

0

不确定第一个错误,但是

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

似乎很奇怪。只能有一个循环变量,而不是一对。

于 2013-07-29T12:52:38.663 回答