Q:

mySQL stored procedural with variable method, query and limit

Hello I'm quite new to mySQL and I'm trying to write a stored procedure. I've searched on the internet to questions alike this one but I couldn't find any results for this.
I'm trying to make search function for my webapplication where you can search in the database for results, yet there are different methods to search on (By name, last name, adres, etc). The query should also have a limit in results (1, 5, 10, 20). My idea was something like this:
CREATE PROCEDURE SelectTopResults @query varchar(60), @method varchar(20), @limited int(3)
AS
SELECT * FROM customer WHERE @method = %@query% LIMIT @limited
GO;

This doesn't run. Is this idea of the procedure correct? And how should I fix it then? Or is there another better way to do this?
Thanks in advance.

Edit:
This is to be accessed with PHP.
My idea was to write a code that basically does:
$sql = 'EXEC SelectTopResults @method = ?, @query = ?, @limited = ?;'

Edit 2:
Solved, thanks a lot! :)
For those interested in the code:
DELIMITER //
CREATE PROCEDURE selectTopResults(IN col varchar(64), IN limited int(3), searchquery varchar(60))
BEGIN
    SET @s = CONCAT("SELECT * FROM customer WHERE ",col," LIKE '%",searchquery,"%' LIMIT ",limited);
    PREPARE stmt FROM @s;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
END
//
DELIMITER ;

Also works with wildcards and can be called upon with:
CALL selectTopResults('column_name', 5, 'query');

whereby 5 is the limit

A:

Welcome to the forum. You've got it a bit wrong - there is something about stored procedures in the MySQL manual, but I can never find it in the first attempt. Luckily, there are many tutorials, if you search for them in google, bing or whatever. Try this, for example: https://www.mysqltutorial.org/introduction-to-sql-stored-procedures.aspx
So, to get your procedure to work:
DELIMITER $$

CREATE PROCEDURE SelectTopResults (
  query varchar(60), 
  method varchar(20), 
  limited int(3)
)
BEGIN
  ...
END$$

DELIMITER ;

It is normal to use the DELIMITER statement to change what signifies the end of a statement - otherwise, you are going to get error messages when you type in the statements that go into the procedure. Next, you need round brackets around your parameters and no @ before their names.
You may wonder why I break the parameter list out over several lines; this is just my style - I feel it makes it easier to read where the parameters start and end. Finally, about your SELECT statement:
SELECT * FROM customer WHERE @method = %@query% LIMIT @limited

I'm not sure what you are trying here - firstly, you need to loose the @s - that is for variables you set with SET, I believe (I'm writing from memory, as I am not near my manuals), not for variables and parameters in a procedure or function. But more importantly, you can't use the parameter method as the name of a table column - for that you need to construct the SELECT as a string and execute. This is called 'dynamic SQL', as far as I recall; I think you can do this in MySQL, but I am not sure without looking it up.
I hope this helps, and hopefully somebody with more immediate knowledge can help you better.

