如何在Mysqli中的UNION准备好的语句中绑定结果?

时间:2018-06-30 04:32:09

标签: php mysql prepared-statement union

如果两个联合查询中都存在行选择,则Mysqli如何绑定结果。假设有这样的查询

        $construct .="(rated in ($age_csph) or rated in ($age_csph)
          or rated in ($age_csph) or rated in ($age_csph) or rated in ($age_csph)
          or rated in ($age_csph) or rated in ($age_csph))";

$stmt1 = $conn->prepare("(SELECT id,name,year FROM info WHERE $construct) union all (SELECT id,name,year FROM show WHERE $construct) ORDER BY year desc"); 

    array_unshift($total_params, $param_string);  // prepend the type values string

    $ref = [];  // add references
    foreach ($total_params as $i => $v) {
        $ref[$i] = &$total_params[$i];  // pass by reference as required/advised by the manual
    }

    call_user_func_array([$stmt, 'bind_param'], $ref);    

      $stmt->execute();
      $stmt->bind_result($id1,name1,$year1);

      $count = 0;
      while ($stmt->fetch()){
       echo $year1;
           $count++;
        } 
        $foundnum=$count; 

       }

我想知道如果两个选择都匹配,结果如何绑定。 仅有一个

$stmt->bind_result($id1,name1,$year1);

请有人给我解释一下。

0 个答案:

没有答案