Here is the updated question:
the current query is doing something like:
$sql1 = \"TRUNCATE TABLE fubar\";
$sql2 = \"CREATE TEMP
execute any query if table exists.
Usage: call Edit_table(database-name,table-name,query-string);
DELIMITER $$ DROP PROCEDURE IF EXISTS `Edit_table` $$ CREATE PROCEDURE `Edit_table` (in_db_nm varchar(20), in_tbl_nm varchar(20), in_your_query varchar(200)) DETERMINISTIC BEGIN DECLARE var_table_count INT; select count(*) INTO @var_table_count from information_schema.TABLES where TABLE_NAME=in_tbl_nm and TABLE_SCHEMA=in_db_nm; IF (@var_table_count > 0) THEN SET @in_your_query = in_your_query; #SELECT @in_your_query; PREPARE my_query FROM @in_your_query; EXECUTE my_query; ELSE select "Table Not Found"; END IF; END $$ DELIMITER ;
More on Mysql