如何使用phpmyadmin编写存储过程以及如何通过php使用它?
我希望能够使用 phpMyAdmin 创建存储过程,然后通过 php 使用它。
但我不知道该怎么办?
据我所知,我发现我们无法通过phpMyAdmin
来管理存储过程。
还有什么其他工具可以管理存储过程?
我什至不确定通过 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
由于存储过程是使用查询创建、更改和删除的,因此您实际上可以使用 phpMyAdmin 来管理它们。
要创建存储过程,您可以使用以下命令(根据需要进行更改):
并确保将 SQL 选项卡上的“分隔符”字段设置为 //。
创建存储过程后,它将出现在表下方的例程字段集中(在“结构”选项卡中),并且您可以轻松更改/删除它。
要使用 PHP 中的存储过程,您必须执行 CALL 查询,就像在普通 SQL 中执行的操作一样。
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) :
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.
我想没有人提到这一点,所以我就写在这里。在 phpMyAdmin 4.x 中,顶行“例程”选项卡下有“添加例程”链接。此链接将打开一个弹出对话框,您可以在其中编写存储过程,而不必担心分隔符或模板。
添加例程
请注意,对于简单的测试存储过程,您可能希望删除已经给出的默认参数,或者您可以简单地为其设置一个值。
I guess no one mentioned this so I will write it here. In phpMyAdmin 4.x, there is "Add Routine" link under "Routines" tab at the top row. This link opens a popup dialog where you can write your Stored procedure without worrying about delimiter or template.
Add Routine
Note that for simple test stored procedure, you may want to drop the default parameter which is already given or you can simply set it with a value.
试试这个
try this
尝试 Toad for MySQL - 它免费且非常棒。
Try Toad for MySQL - its free and its great.
我让它在 phpAdmin 中工作,但只有当我删除“记录数”短语时。
在我的 phpAdmin 版本中,我可以看到用于更改分隔符的框。
为了查看数据库中的过程,我去了 phpAdmin 主页,然后是 information_schema 数据库,然后是例程表。
I got it to work in phpAdmin , but only when I removed the "Number of records " phrase.
In my version of phpAdmin I could see the box for changing the delimiters.
Also to see the procedure in the database i went to the phpAdmin home, then information_schema database and then the routines table.
新版本的 phpMyAdmin (3.5.1) 对存储过程的支持有了更好的表现;包括:编辑、执行、导出、PHP代码创建和一些调试。
确保您在 config.inc.php 中使用 mysqli 扩展
打开任意数据库,您将在顶部看到一个名为例程的新选项卡,然后选择添加例程。
我所做的第一个测试产生了以下错误消息:
Ciuly 的博客< /a> 提供了一个很好的解决方案,假设您有命令行访问权限。如果不这样做,不确定如何解决它。
The new version of phpMyAdmin (3.5.1) has much better support for stored procedures; including: editing, execution, exporting, PHP code creation, and some debugging.
Make sure you are using the mysqli extension in config.inc.php
Open any database, you'll see a new tab at the top called Routines, then select Add Routine.
The first test I did produced the following error message:
Ciuly's Blog provides a good solution, assuming you have command line access. Not sure how you would fix it if you don't.
从客户中选择计数(id);
结尾
SELECT count(id) from customer;
END
以上所有答案都是做出一定的假设。 1and1 中存在基本问题,某些其他托管提供商正在使用非常旧的 phpMyAdmin 版本,并且存在定义分隔符的问题;并且无法从 phpMyAdmin 更改它。 方法
希望这有帮助
All the answers above are making certain assumptions. There are basic problems in 1and1 and certain other hosting providers are using phpMyAdmin versions which are very old and have an issue that defined delimiter is ; and there is no way to change it from phpMyAdmin. Following are the ways
Hope this helps
在本地服务器上,您的以下查询将起作用,
但在生产服务器上可能不起作用。取决于您使用的 mysql 版本。我在 powweb 服务器上遇到了同样的问题,我删除了分隔符和开始关键字,它工作正常。
看看下面的查询
On local server your following query will work
but on production server it might not work. depend on mysql version you are using. I had a same problem on powweb server, i removed delimiter and begin keywords, it works fine.
have a look at following query