如何使用phpmyadmin编写存储过程以及如何通过php使用它? [英] How to write a stored procedure using phpmyadmin and how to use it through php?
问题描述
我希望能够使用phpMyAdmin
创建存储过程,以后再通过php使用它.
I want to be able create stored procedures using phpMyAdmin
and later on use it through php.
据我了解,我发现我们无法通过phpMyAdmin
管理存储过程.
From what I know, I found out that we cannot manage stored procedures through phpMyAdmin
.
还有哪些其他工具可以管理存储过程?
我什至不确定通过PHP使用存储过程是否是更好的选择. 有什么建议吗?
I am not even sure if it is better option to use stored procedure through PHP. Any suggestion?
推荐答案
由于使用查询创建,更改和删除了存储过程,因此您实际上可以使用phpMyAdmin对其进行管理.
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//
并确保将"SQL"标签上的分隔符"字段设置为//.
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.
要使用PHP中的存储过程,必须执行CALL查询,就像在普通SQL中一样.
To use the stored procedure from PHP you have to execute a CALL query, just like you would do in plain SQL.
这篇关于如何使用phpmyadmin编写存储过程以及如何通过php使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!