title: MySql #1243 error while executing it through phpMyAdmin
body: <p>I am trying to execute this code in phpMyAdmin. But, I'm getting following error</p>
  
  <p>#1243 - Unknown prepared statement handler (stmt) given to EXECUTE</p>
  
  <pre><code>    SET @sql = NULL;
  SELECT
    GROUP_CONCAT(DISTINCT
      CONCAT(
        'count(distinct CASE WHEN topic = ''',
        topic,
        ''' THEN t2.id END) AS `',
        topic, '`'
      )
    ) INTO @sql
  FROM
  (
    select count(distinct id) total, topic
    from table2 
    group by topic
    order by total desc
    limit 2
  ) d;
  
  SET @sql 
    = CONCAT('SELECT t1.year, ', @sql, ' 
              from table1 t1
              left join table2 t2
                on t1.id = t2.id
              group by t1.year');
  
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
  </code></pre>
  
  <p>Check out <a href="http://sqlfiddle.com/#!2/66a44/1" rel="nofollow">fiddle</a> for implementation.</p>
  
  <p>How to fix this? Also, as a com-mentor mentioned this will work when sent through script. Any ideas how do I script in PHP?</p>