Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a stored procedure using phpmyadmin and how to use it through php?

I want to be able create stored procedures using phpMyAdmin and later on use it through php.

But I dont know how to?

From what I know, I found out that we cannot manage stored procedures through phpMyAdmin.

What other tool can manage stored procedure?

I am not even sure if it is better option to use stored procedure through PHP. Any suggestion?

like image 337
Starx Avatar asked May 17 '10 03:05

Starx


People also ask

Where is stored procedure stored in phpMyAdmin?

You can view your created procedures under 'Routines' tab itself. Show activity on this post. In phpMyAdmin you can create the stored procedure in the SQL window.

How can we call stored procedure with parameters in PHP with SQL server?

To call a stored procedure from a PHP application, you execute an SQL CALL statement. The procedure that you call can include input parameters (IN), output parameters (OUT), and input and output parameters (INOUT).

Does phpMyAdmin use PHP?

phpMyAdmin is a free software tool written in PHP that is intended to handle the administration of a MySQL or MariaDB database server. You can use phpMyAdmin to perform most administration tasks, including creating a database, running queries, and adding user accounts.


1 Answers

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.

like image 104
wimvds Avatar answered Oct 10 '22 12:10

wimvds