PHP Error 2014: Commands out of sync; you can't run this command now

Discussion in 'General Webmaster Support' started by camelCase, Aug 21, 2013.

  1. camelCase

    camelCase The Case of the Mysterious Camel.

    Ratings:
    +357 / 0 / -0
    Okay, so, I've got this school project I've been working on using my laptop as a server. However, I cannot submit it without putting it on the school's servers. My lecturer finally gave me access to it and I finally was able to start migrating my project there.

    After fixing a tonne of smaller issues like default charset mismatch and case sensitivity issues, this particular problem came along and has me stumped. I spent a few hours running through my code, looking through PHP documentation and mangling my code to print out walls of debug text and finally re-produced the bug with as little code as possible.

    Here's the PHP code:
    Code:
    <?php
        define("HOST", "someHost");
        define("USER", "someUser");
        define("PASS", "somePass");
        define("DB"  , "someDB");
        $conn = mysqli_connect(HOST, USER, PASS, DB);
     
        $stmt1 = $conn->stmt_init();
        if (!$stmt1->prepare("CALL P_Topics_Get(33);")) {//If I uncomment this, I get an error when trying to prepare $stmt2
        //if (!$stmt1->prepare("SELECT 0, 'name', 1, 2, 3;")) {//If I uncomment this, I DON'T get an error anywhere
            echo "Failed to prepare 1: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        if (!$stmt1->execute()) {
            echo "Failed to execute 1: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        if (!$stmt1->store_result()) {
            echo "Failed to store 1: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        $stmt1->bind_result($id, $name, $step, $decAmt, $maxAmt);
        if (!$stmt1->fetch()) {
            echo "Failed to fetch 1: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        echo "$id, $name, $step, $decAmt, $maxAmt<br>";
        $stmt1->free_result();
        $stmt1->close();
     
        $stmt2 = $conn->stmt_init();
        if (!$stmt2->prepare("SELECT 2;")) {
            echo "Failed to prepare 2: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        if (!$stmt2->execute()) {
            echo "Failed to execute 2: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        if (!$stmt2->store_result()) {
            echo "Failed to store 2: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        $stmt2->bind_result($val2);
        if (!$stmt2->fetch()) {
            echo "Failed to fetch 2: " . $conn->errno . ", " . $conn->error;
            exit;
        }
        echo "Val 2: " . $val2 . "<br>";
        $stmt2->free_result();
        $stmt2->close();
     
        echo "success";
    ?>
    
    P_Topics_Get() is a simple select statement from a table:
    Code:
    SELECT
      *
    FROM
      Topics t
    WHERE
      t.id = topicId
    LIMIT 1;
    
    So.. Yeah. This works on my localhost with no errors but messes everything up on the school's machine. This is the first time I have ever encountered the 2014 error.. And it's only 2013! (/joke)

    Anyone know what's up?
     
  2. monoVertex

    monoVertex I'm back!

    Ratings:
    +459 / 0 / -0
    First, with your current code, with commented lines and all, what line exactly generates your error? The first prepare?

    Also, I found this. Could you remove the ";"s from your queries and try again?

    Code:
    CALL P_Topics_Get(33);
    would be translated as
    Code:
    SELECT  * FROM Topics t WHERE t.id = topicId LIMIT 1;;
    , I think.

    Another thing, do you have access to the server? Can you make sure you have the latest MySQL client and server versions?
     
    • Like Like x 1

Share This Page