I have an stored procedure like this:
SET @query = CONCAT('insert into tblcommodity (id , idname , count)values (',p1, p2,p3,')');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
But when I want to run it, it has this error:
> Procedure execution failed 1136 - Column count doesn't match value
> count at row 1
and another thing is that when I just run the insert code it runs!
plz help me.
With all due respect, the way you do it kindof defeats the whole purpose of prepared statements. I'd use this form instead:
SET @query = 'INSERT INTO tblcommodity (id, idname, count) VALUES (?, ?, ?)';
PREPARE stmt FROM @query;
EXECUTE stmt USING @p1, @p2, @p3;
It should be
SET @query = CONCAT('insert into tblcommodity (id , idname , count)values (',',',p1,',', p2,',',p3,')');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With