MySQL: Error in SQL: Commands out of sync; you can’t run this command now

Today I was programming MySQL via PHP and I received an error “Error in SQL: Commands out of sync; you can’t run this command now”. It turned out the problem was that a previous mulit_query had mysqli_results that hadn’t been freed. This article helped me solve the problem, and now my batch mode SQL processor looks like this:

  public function execute_batch( $sql ) {

    $this->write_count++;

    if ( ! $this->link->multi_query( $sql ) ) {

      $this->throw_error( $sql );

    }

    if ( $this->link->more_results() ) {

      do {
        $result = $this->link->use_result();
        if ( $result instanceof mysqli_result ) {
          $result->free();
        }
      }
      while ( $this->link->more_results() && $this->link->next_result() );

    }
  }

This code executes the SQL batch and then frees any mysqli_results that result from the query batch.

INFO: task dpkg:27497 blocked for more than 120 seconds.

I’ve been getting this error from time to time on my Ubuntu server:

 INFO: task dpkg:27497 blocked for more than 120 seconds.

I did some research and it turns out this is related to a bug in the dpkg system, and apparently it’s been fixed already (but not rolled out as part of Ubuntu yet).

Look forward to the fixed being rolled out, because the implication of the bug at the moment is that my system can hang for long periods of time while I’m installing software with apt-get.