How to Write a Stored Procedure Using PHPmyadmin and How to Use It Through PHP

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.

Sample Image

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



Leave a reply



Submit