Question: > 
> MySQL Error: Commands out of sync; you can't run this command now
> 
> 
> 

I get the above error when I try to execute an SQL Procedure more than once each time.

I've found that it has something to with the "store result", so I've been trying to figure it out for a while, but I haven't succeeded yet.

Here is my PHP code:

```
$query = "CALL GetObjectsValue(".$FormID.")";

if( $res = $mysqli->query($query) )
{
    $mysqli->store_result();

    while ($row = $res->fetch_assoc()) 
    {

        ...

    }
    $res->free();
}

```

Answer: 
For some reason, for recordset from stored procedures one has to loop through it using next\_result() command. This is not the case if recordset comes directly by execution of SQL query (SELECT).

```
$query="CALL GetObjectsValue($FormID)";
if($res=$mysqli->query($query))
{
  do
  {
    $row = $res->fetch_assoc()
    ...
  }
  while($mysqli->next_result()); //loop through recordset

  $res->free();
}

```
Change 

```
$query = "CALL GetObjectsValue(".$FormID.")";     

```

to

```
$query = "CALL GetObjectsValue("$FormID")";  

```

Notice the `$FormID` without the dots.