mysqli中union prepared语句的结果是如何绑定的?

huwehgph  于 2021-06-24  发布在  Mysql
关注(0)|答案(0)|浏览(176)

如果两个联合查询中都有行选择,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; 

       }

我想知道如果两个select中都有匹配,结果是如何绑定的。只有一个

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

请有人给我解释一下。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题