Using one variable doesn't give me an error. with two variables it gives me a syntax error.
set @a= '...';
set @b = '...';
PREPARE stm1 FROM
'SELECT *
FROM ?
WHERE username = ?';
EXECUTE stm1 USING @a, @b;
Error Code: 1064. You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near '? WHERE username = ?' at line 2
other questions didn't help.
thanks
You can't use a parameter for a table name. You have to use concatenation to substitute a variable for the table.
PREPARE stm1 FROM CONCAT(
'SELECT *
FROM `', @a, '`
WHERE username = ?');
EXECUTE stmt1 USING @b;