Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL #1243 Unknown prepared statement handler (stmt) given to EXECUTE

Tags:

sql

mysql

I am following this tutorial on my installed version of MySQL, but it's throwing me an error:

SET @sql = NULL;
SELECT
  GROUP_CONCAT(DISTINCT
    CONCAT(
      'MAX(IF(property_name = ''',
      property_name,
      ''', value, NULL)) AS ',
      property_name
    )
  ) INTO @sql
FROM
  properties;
SET @sql = CONCAT('SELECT item_id, ', @sql, ' FROM properties GROUP BY item_id');

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

I am pasting it on SQL editor in phpMyAdmin.

I followed the suggestion. No errors shown but here's the result:

SELECT item_id
,MAX(IF(property_name = 'color', value, NULL)) AS color
,MAX(IF(property_name = 'size', value, NULL)) AS size
,MAX(IF(property_name = 'weight', value, NULL)) AS weight 
FROM properties GROUP BY item_id
like image 450
Mr A Avatar asked Apr 18 '13 05:04

Mr A


People also ask

What is MySQL used for?

MySQL is a tool used to manage databases and servers, so while it's not a database, it's widely used in relation to managing and organising data in databases.

What is difference between SQL and MySQL?

SQL is primarily used to query and operate database systems. MySQL allows you to handle, store, modify and delete data and store data in an organized way. SQL does not support any connector. MySQL comes with an in-built tool known as MySQL Workbench that facilitates creating, designing, and building databases.

Is MySQL DBMS or database?

MySQL is a database management system. It may be anything from a simple shopping list to a picture gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server.

Is MySQL still free?

MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses.


2 Answers

If you have access to a MySQL command-line, I think you'll find your SQL code is fine (as long as @sql doesn't equal NULL) and the issue is with phpMyAdmin. Another idea is to wrap the code in a stored procedure and then CALL the procedure.

like image 130
udog Avatar answered Sep 21 '22 03:09

udog


You need to remove the DEALLOCATE PREPARE stmt; from your query until after the query runs.

DEALLOCATE cancels the statement before it has a chance to run.

like image 33
Dustin Avatar answered Sep 18 '22 03:09

Dustin