我知道很多时候这个问题已得到解答。我见过anwseres但仍然无法理解出了什么问题。这里是一段代码 -
$var =$_POST['feature'];
$status = 'passed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata WHERE testCase REGEXP :var GROUP BY family ORDER BY family' );
$allTest->bindValue(":var", "^$var", PDO::PARAM_STR);
$allTest->execute(array(':status' => $status));
while($row = $allTest->fetch(PDO::FETCH_ASSOC))
{
foreach($row as $key)
{
$totalTestPassed[] = $key;
}
}
print_r($totalTestPassed);
我在网上收到此错误 - $allTest->execute(array(':status' => $status));
请指导我收到此错误的原因。
答案 0 :(得分:0)
试试这个
$var =$_POST['feature'];
$status = 'passed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata WHERE testCase REGEXP :var GROUP BY family ORDER BY family' );
$allTest->bindValue(":var", "^$var", PDO::PARAM_STR);
$allTest->bindValue(":status", $status);
$allTest->execute();
while($row = $allTest->fetch(PDO::FETCH_ASSOC))
{
foreach($row as $key)
{
$totalTestPassed[] = $key;
}
}
print_r($totalTestPassed);
你也可以通过这样做取消bindParam
$allTest->execute(array(':status' => $status, ':var' => ^$var));
默认情况下,它会将两个字符串作为字符串传递给查询,而不是单独定义
答案 1 :(得分:0)
试试这个:
$status = 'passed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata WHERE testCase REGEXP :var GROUP BY family ORDER BY family' );
$allTest->bindValue(":var", $var, PDO::PARAM_STR);
$allTest->bindValue(":status", $status, PDO::PARAM_STR);
$allTest->execute();