doushi1957 2016-03-22 13:52
浏览 48
已采纳

Mysqli多查询错误

I need to execute two or more queries at a time, fetch them one after another.

Then I need to bind param and bind result in each one of them.

I am trying this way but getting error.

$query="
SELECT 
`date`, `ip`, AVG(`value`)
FROM `stats`.`stats`    
WHERE `uid`=?
GROUP BY `date`, `ip`;
";

$query.="
SELECT 
`category`, `ip`, AVG(`value`)
FROM `stats`.`stats`    
WHERE `uid`=?
GROUP BY `category`, `ip`;
";

$prepare = mysqli_multi_query($connection, $query);
mysqli_stmt_bind_param($prepare, 'ss', $uid,$uid);
mysqli_stmt_execute($prepare) or trigger_error(mysqli_error($connection), E_USER_ERROR);

Then in html part I need to fetch result of these one after another

//fetch first query result
while (mysqli_stmt_fetch($prepare)):
mysqli_stmt_store_result($prepare);
mysqli_stmt_bind_result($prepare, $date,$ip,$value);
mysqli_free_result($result);
endwhile;

//fetch second query result
while (mysqli_next_result($prepare)):
while (mysqli_stmt_fetch($prepare));
mysqli_stmt_store_result($prepare);
mysqli_stmt_bind_result($prepare, $category,$ip,$value);
mysqli_free_result($result);
endwhile;

But its not working showing multiple errors.

 Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in
 Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in
 Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? GROUP BY `date`,`ip` ) ..

Please see and suggest any possible way to do this.

Thanks

  • 写回答

1条回答 默认 最新

  • duanaixuan7385 2016-03-22 14:00
    关注

    I need to execute two or more queries at a time

    You don't.

    And, therefore, you should use just regular prepare/execute for your queries, running them one by one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?