0

这是我的代码

my $results = $dbh->selectall_hashref('SELECT * FROM sample.teachers where term like "$searchterm%"', 'teacher');
my $searchedresults= "";
foreach my $e (keys %$results) {
    print "$e\n";
    print "searching\n";
    $searchedresults = $e;
    }
    print $searchresult."\n";

我正在尝试从 mysql 服务器中的表中搜索。但似乎它不起作用我使用硬编码的方式通过用普通字符串替换 $searchterm 来测试它并且有效。但是我需要使用 $searchterm 但我不知道为什么它不能工作

4

1 回答 1

2
my $results = $dbh->selectall_hashref(
   'SELECT * FROM sample.teachers where term like '.$dbh->quote("$searchterm%"),
   'teacher'
);

或者

my $results = $dbh->selectall_hashref(
   'SELECT * FROM sample.teachers where term like ?,
   'teacher',
   undef,
   "$searchterm%"
);
于 2013-04-23T03:19:02.123 回答