Commands out of sync; you can't run this command now

前端 未结 21 2581
庸人自扰
庸人自扰 2020-11-21 11:35

I am trying to execute my PHP code, which calls two MySQL queries via mysqli, and get the error \"Commands out of sync; you can\'t run this command now\".

Here is th

21条回答
  •  無奈伤痛
    2020-11-21 11:59

    Another cause: store_result() cannot be called twice.

    For instance, in the following code, Error 5 is printed.

    stmt_init();
    if ($stmt->error) printf("Error 1 : %s\n", $stmt->error);
    
    $stmt->prepare("select 1");
    if ($stmt->error) printf("Error 2 : %s\n", $stmt->error);
    
    $stmt->execute();
    if ($stmt->error) printf("Error 3 : %s\n", $stmt->error);
    
    $stmt->store_result();
    if ($stmt->error) printf("Error 4 : %s\n", $stmt->error);
    
    $stmt->store_result();
    if ($stmt->error) printf("Error 5 : %s\n", $stmt->error);
    

    (This may not be relevant to the original sample code, but it can be relevant to people seeking answers to this error.)

提交回复
热议问题