How to write a stored procedure using phpmyadmin and how to use it through php?
Since a stored procedure is created, altered and dropped using queries you actually CAN manage them using phpMyAdmin.
To create a stored procedure, you can use the following (change as necessary) :
CREATE PROCEDURE sp_test()
BEGIN
SELECT 'Number of records: ', count(*) from test;
END//
And make sure you set the "Delimiter" field on the SQL tab to //.
Once you created the stored procedure it will appear in the Routines fieldset below your tables (in the Structure tab), and you can easily change/drop it.
To use the stored procedure from PHP you have to execute a CALL query, just like you would do in plain SQL.
How to write a stored procedure in phpMyAdmin?
In phpMyAdmin you can create the stored procedure in the SQL window.
You may have to set the delimieter to something like "$$" instead of the default ";". You can change this from the bottom of the SQL window.
Also you can refer this: http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx
Error while creating a procedure in phpmyadmin
Try using a DELIMITER
statement:
DELIMITER $$
CREATE PROCEDURE insertData (
in_Name varchar(255),
in_Description text
)
BEGIN
INSERT INTO categories(name, description)
VALUES (in_Name, in_Description);
END;$$
DELIMITER ;
Notice that I also renamed in the input parameters so they are less likely to be confused with column names. This is a good practice when writing stored procedures and functions.
Related Topics
Trouble Using Posix_Kill in PHP
How to Make Number_Format() Not to Round Numbers Up
Bcrypt and Randomly Generated Salts
How to Use "Dependency Injection" in Simple PHP Functions, and Should I Bother
How to Convert JSON to Xml in PHP
Use a Variable to Define a PHP Function
Warning: Session_Start() Failed: No Such File or Directory
PHP Failed to Open Stream: Is a Directory
PHP Commands Out of Sync Error
Binding Parameters for Where in Clause with Pdo
Static' Keyword Inside Function