title: MySQL stored procedure caused `Commands out of sync`
body: <p>Call procedure works all right in MySQL terminal, but in PHP, caused <code>Commands out of sync; you can't run this command nowCommands out of sync; you can't run this command now</code></p>
  
  <p>My procedure is </p>
  
  <pre><code>delimiter $$
  create procedure getMostSimilar (IN vU_ID INT, IN voffset INT, IN vsize INT)
  BEGIN
  set @offset = voffset;
  set @size = vsize;
  set @uid = vU_ID;
  prepare SimilarStmt from
  "SELECT U_ID, getSimilarity(U_ID, ?) AS similar FROM Answer WHERE U_ID != ? GROUP BY U_ID ORDER BY similar DESC LIMIT ?, ?";
  execute SimilarStmt using @uid, @uid, @offset, @size; 
  deallocate prepare SimilarStmt;
  END
  $$
  </code></pre>
  
  <p>where getSimilarity is a function.</p>
  
  <p>In PHP:</p>
  
  <pre><code>function getMostSimilar($U_ID, $offset, $size){
      $query = sprintf("CALL getMostSimilar(%s, %s, %s)",
                  $U_ID, $offset, $size);
      $result = mysql_query($query);
      print mysql_error();
      if (!$result){
          return $query;
      }
      $ans = array();
      $len = 0;
      while($row = mysql_fetch_assoc($result)){
          $ans[$len] = $row;
          $len++;
      }
      return $ans;
  }
  </code></pre>
  
  <p>What should I do now? Thanks!</p>