如何从Perl调用MySQL存储过程? [英] How do I call MySQL stored procedures from Perl?

查看:158
本文介绍了如何从Perl调用MySQL存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Perl调用MySQL存储过程?存储过程功能对于MySQL来说是相当新的功能,而Perl的MySQL模块似乎尚未赶上.

How do I call MySQL stored procedures from Perl? Stored procedure functionality is fairly new to MySQL and the MySQL modules for Perl don't seem to have caught up yet.

推荐答案

产生数据集的MySQL存储过程需要您使用Perl DBD :: mysql 4.001或更高版本. ( http://www.perlmonks.org/?node_id=609098 )

MySQL stored procedures that produce datasets need you to use Perl DBD::mysql 4.001 or later. (http://www.perlmonks.org/?node_id=609098)

下面是一个可以在较新版本中运行的测试程序:

Below is a test program that will work in the newer version:

mysql> delimiter //
mysql> create procedure Foo(x int)
  -> begin
  ->   select x*2;
  -> end
  -> //

perl -e 'use DBI; DBI->connect("dbi:mysql:database=bonk", "root", "")->prepare("call Foo(?)")->execute(21)'

但是如果您的DBD :: mysql版本太旧,则会得到如下结果:

But if you have too old a version of DBD::mysql, you get results like this:

DBD::mysql::st execute failed: PROCEDURE bonk.Foo can't return a result set in the given context at -e line 1.

您可以使用CPAN安装最新的DBD.

You can install the newest DBD using CPAN.

这篇关于如何从Perl调用MySQL存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆