我有一个数组family
,如 -
Array ( [0] => 2510-24 [1] => 2510-48 [2] => 2510G [3] => 2520 [4] => 2520G [5] => 2530ya [6] => 2530ya3 [7] => 2530yb [8] => 2610 [9] => 2615 [10] => 2620 [11] => 2626 [12] => 2650 [13] => 2810 [14] => 2900 [15] => 2910 [16] => 2915 [17] => 2920 [18] => 3500 [19] => 3500jr [20] => 3500strk [21] => 3800 [22] => 3800FIPS [23] => 4100 [24] => 4200 [25] => 5300 [26] => 5400 [27] => 5400FIPS [28] => 5400R [29] => 5400RFIPS [30] => 5900 [31] => 6100 [32] => 6200 [33] => 6600 [34] => 8200 [35] => 8200FIPS [45] => Mako [46] => MSM317 [47] => MSM430 [48] => MSM460 [49] => MSM466 [50] => MSM720 [51] => MSM760 [52] => MSM765 [53] => MSM775 [54] => stack-AR [55] => stack-TA )
现在我有一个db查询,其中我只想查询我的数据库,其中family是上述之一。
我累了 -
$status = 'passed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata WHERE family IN (".$family.") GROUP BY family ORDER BY family' );
$allTest->execute(array(':status' => $status));
甚至内爆 -
$family = implode(',',$family);
// Finding passed test cases on each platform
$status = 'passed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata WHERE family IN ('.$family.') GROUP BY family ORDER BY family' );
$allTest->execute(array(':status' => $status));
但这不起作用。这有什么不对? 做同样事情的更好方法是什么?
答案 0 :(得分:-2)
$imploded_family = implode(',', array_map([$conn, 'quote'], $family));
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata WHERE family IN ('.$imploded_family.') GROUP BY family ORDER BY family' );