title: MySQL prepared statements with parameters not returning data
body: <p>I have been trying to make parameterized prepared statements work. The first function only presents the header row with the column names and does not show any daya. The second
  function provides all the data requested. The difference is that the first one uses parameters and the second only uses concatenated strings. The select statements in the first
  function are used for debugging purposes, there are no NULL strings in any of the variables.</p>
  
  <p>I would like to get the parameterized version working properly, I would appreciate any help.</p>
  
  <p>I have already checked out these stackoverflow answers, <a href="https://stackoverflow.com/questions/21801890/how-to-use-multiple-parameters-in-a-mysql-prepared-stored-procedure">Multiple Parameters</a>, <a href="https://stackoverflow.com/questions/746075/mysql-prepared-statement-parameters-and-ordering-queries/746216">mysql Prepare Statement</a>, <a href="https://stackoverflow.com/questions/20034845/whats-the-internals-of-a-prepared-statement-like">Internals of prepared statement</a>, <a href="https://stackoverflow.com/questions/6030614/unable-to-create-prepared-statements-in-mysql?rq=1">unable to create prepared statements</a> (might be the answer to my problem).    </p>
  
  <pre><code>-- -----------------------------------------------------
  -- procedure getAllBookDataWhere2
  -- -----------------------------------------------------
  
  USE `booklibinventory`;
  DROP procedure IF EXISTS `booklibinventory`.`getAllBookDataWhere2`;
  
  DELIMITER $$
  USE `booklibinventory`$$
  CREATE PROCEDURE `getAllBookDataWhere2` 
  (
      IN whereStr VARCHAR(256)
  )
  BEGIN
  
      DECLARE finalQuery VARCHAR(4096);
      DECLARE selectedFields, leftJoinTables, joinOnFields VARCHAR(1024);
      DECLARE whereClause, orderByClause VARCHAR(256);
  
      SET @selectedFields = allBooksSelectFields();
      SET @jointTables4Query = allBooksDataTables();
      -- orderBy may become a parameter in the future.
      SET @orderByClause = ' a.LastName, a.FirstName, s.SeriesName, v.VolumeNumber, t.TitleStr';
      SET @whereclause = whereStr;
  
      -- @selectedFields and @jointTables4Query are concatenated because they don't change,
      -- @whereClause and @orderByClause can change and therefore are parameters.
  
  SELECT @orderByClause;
  SELECT @whereClause;
  
      SET @finalQuery = CONCAT('SELECT ', @selectedFields);
      SET @finalQuery = CONCAT(@finalQuery, ' FROM bookinfo AS BKI ');
      SET @finalQuery = CONCAT(@finalQuery, @jointTables4Query);
      SET @finalQuery = CONCAT(@finalQuery, ' WHERE ?  ORDER BY ? ;');
  
  SELECT @finalQuery;
  
      PREPARE stmt FROM @finalQuery;
      EXECUTE stmt USING @whereClause, @orderByClause;
      DEALLOCATE PREPARE stmt;
  
  END$$
  
  DELIMITER ;
  
  -- -----------------------------------------------------
  -- procedure getAllBookDataWhere
  -- -----------------------------------------------------
  
  USE `booklibinventory`;
  DROP procedure IF EXISTS `booklibinventory`.`getAllBookDataWhere`;
  
  DELIMITER $$
  USE `booklibinventory`$$
  CREATE PROCEDURE `getAllBookDataWhere` 
  (
      IN whereStr VARCHAR(256)
  )
  BEGIN
  
      DECLARE finalQuery VARCHAR(4096);
      DECLARE selectedFields, leftJoinTables, joinOnFields VARCHAR(1024);
      DECLARE whereClause, orderByClause VARCHAR(256);
  
      SET @selectedFields = allBooksSelectFields();
      SET @jointTables4Query = allBooksDataTables();
      -- orderBy may become a parameter in the future.
      SET @orderByClause = ' ORDER BY a.LastName, a.FirstName, s.SeriesName, v.VolumeNumber, t.TitleStr;';
      SET @whereclause = CONCAT(' WHERE ', whereStr);
  
      -- @selectedFields and @jointTables4Query are concatenated because they don't change,
      -- @whereClause and @orderByClause can change and therefore are parameters.
  
  
      SET @finalQuery = CONCAT('SELECT ', @selectedFields);
      SET @finalQuery = CONCAT(@finalQuery, ' FROM bookinfo AS BKI ');
      SET @finalQuery = CONCAT(@finalQuery, @jointTables4Query);
      SET @finalQuery = CONCAT(@finalQuery, @whereClause);
      SET @finalQuery = CONCAT(@finalQuery, @orderByClause);
  
      PREPARE stmt FROM @finalQuery;
      EXECUTE stmt;
      DEALLOCATE PREPARE stmt;
  
  END$$
  
  DELIMITER ;
  </code></pre>