0

我有这个 Perl 代码:

my $cmd = "
  SELECT COUNT(id)
  FROM tblUsers
  WHERE UPPER(username) = UPPER(?) AND password = ?
";

db_connect();
my $sql = $dbh->prepare($cmd);

my $count = 2;

$sql->execute(
  $args{login_username},
  crypt($args{login_password}, $args{login_username})
) or die "SQL Error: ".$sql->errstr;

$sql->bind_columns(\$count);
$sql->fetch;

它返回 0,但应该返回 1

如果我输出以下内容:

$msg = "wrong username/password: $count;$args{login_username};$args{login_password};" . crypt($args{login_password}, $args{login_username});

我得到:

wrong username/password: 0;skeniver;password;skh9dtk2bCasY

crypt部分正是我在数据库中所拥有的。在 MySQL 中运行相同的值返回计数 1。

我真的无法弄清楚这里出了什么问题。

有没有其他人看到我缺少的东西?

4

1 回答 1

0

假设您select返回一个非0值并假设列passwordtblUsersskh9dtk2bCasYfor username= skeniver,请尝试

 $sql->execute($args{login_username}, crypt($args{login_password},$args{login_username}))
        or die "SQL Error: ".$sql->errstr;
 $count = $sql->fetchrow_array();

或者,如果查询有可能返回多行,那么 -

$sql->execute($args{login_username}, crypt($args{login_password},$args{login_username}))
        or die "SQL Error: ".$sql->errstr;
while (($count) = $sql->fetchrow_array()){                          
    print "Count is: $count\n"; 
}
于 2012-08-14T21:33:01.840 回答