我正在编写一个 perl 脚本,该脚本将访问 MySQL 数据库以确定工具是否通过或失败,但当我尝试在代码上获取row_array 时收到错误。
基本上发生的事情是我循环遍历测试列表以查看它们是否通过或失败,因此循环如下所示:
foreach my $test (@tests){
$sth = $dbh_k->prepare("select fn_get_test_status(' $test ');");
$sth->execute();
my @data = $sth->fetchrow_array();
print("$test\n");
print("@data\n");
}
该函数返回字符串“通过”或“失败”,但是我不知道如何取出该字符串并将其合并到我的 Perl 脚本中。
我不断收到错误在第 xx 行的连接或字符串中使用未初始化的值。
有什么建议或想法吗?谢谢
编辑: 我可能有一个作为我的数据类型返回的数组,我如何进入它来检查它的内容?
最佳答案
这是我们在聊天中找到的解决方案:
my $sth = $dbh_k->prepare("select fn_get_test_status(?);");
foreach my $test (@tests){
$sth->execute($test);
my @data = $sth->fetchrow_array();
printf "%s: %s\n", $test, @data;
}
主要问题是'$test'
旁边的空格。
关于sql - Perl DBI SQL 字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106950/