Store Procedures in PHPmyadmin

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

How do I view my stored procedures in phpMyAdmin?

View stored procedures in phpmyadmin:

Query:

SELECT routine_definition
FROM information_schema.routines
WHERE
routine_name = 'procedure_name' AND routine_schema = 'databasename';

Here's how to get there in phpmyadmin.

phpmyadmin screenshot

The routines option is available in phpmyadmin. The link is not visible in PHPmyadmin until you have at least one stored procedure. See the above image and click the routines link under structure tab.

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.

Stored Procedure in mysql phpmyadmin #1064

MySQL IF-clause uses THEN END IF instead of BEGIN and END.

You also might want to use temporary table for the IDBillInfoTable so it works with concurrent use.

IF (idSecondBill  IS NULL) THEN
INSERT INTO bill (id_table, bill_maker, status)
VALUES (idTable2, 1, 0);

SELECT MAX(id) into idSecondBill
FROM bill
WHERE id_table = idTable2 AND status = 0;
END IF;

and temporary table creation:

CREATE TEMPORARY TABLE IDBillInfoTable AS 
SELECT id
FROM bill_info
WHERE id_bill = idSecondBill;

and dropping the temp table

DROP TEMPORARY TABLE IDBillInfoTable;


Related Topics



Leave a reply



Submit