1

I am new to MySQLi. Trying to use prepared statements, but the prepare command fails with "Prepare failed: (2014) Commands out of sync; you can't run this command now" error. Am I not disposing of resources from the first query adequately?

$sql = 'CALL stored_procedure()';

if(!($result = $conn->query($sql))){ die("Error: initial query failed!!!"); }

while($row = $result->fetch_assoc()){ $id = $row['@id']; }

$result->free();

if($id != 0){  
    $sql = "CALL another_stored_procedure (?, ?, ?)";

    if(!($stmt = $conn->prepare($sql))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
        die();

    }else{
        echo "Something was finally prepared!!!";
    }
}
Eko Junaidi Salam
  • 1,663
  • 1
  • 18
  • 26
Ishikawa
  • 177
  • 2
  • 12

0 Answers0