Perl DBI 与 mysql:如何从存储过程获取返回值?
DBD::mysql 是否实现了 bind_param_inout 方法? 我在尝试时收到以下错误消息:
DBD::mysql::st bind_param_inout 失败:输出参数不正确 实施了[for声明“调用 spCreateTransactionRecord(?, ?)" 与 ParamValues: 0=Null!, 1=Null!] at ./db.pl第23行
我的代码:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBI qw(:sql_types);
use Data::Dumper;
my ($dbh, $dsn, $sth, $sql);
my ($RecID, TypeID);
my ($user, $pass) = '';
# Open DB connection
$dsn = "dbi:mysql:database=mp;mysql_read_default_file=$ENV{HOME}/.my.cnf";
$dbh = DBI->connect($dsn, $user, $pass,
{RaiseError=>1, AutoCommit=>0, ShowErrorStatement=>1})
|| die "DB open error: $DBI::errstr";
# Call stored procedure
$sql = "call spCreateTransactionRecord(?, ?)";
$sth = $dbh->prepare($sql);
$sth->bind_param_inout(2, \$p_RecID, 11, {TYPE=>SQL_INTEGER});
$sth->execute($p_TypeID) || print $sth->errstr;
# Disconnects
$dbh->commit();
$dbh->disconnect;
存储过程声明为:
CREATE PROCEDURE spCreateTransactionRecord (
IN p_TypeID INTEGER,
OUT p_RecID INTEGER
)
Does DBD::mysql implement the bind_param_inout method?
I am getting the following error messages when trying it out:
DBD::mysql::st bind_param_inout
failed: Output parameters not
implemented [for Statement "call
spCreateTransactionRecord(?, ?)" with
ParamValues: 0=Null!, 1=Null!] at
./db.pl line 23
My code:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBI qw(:sql_types);
use Data::Dumper;
my ($dbh, $dsn, $sth, $sql);
my ($RecID, TypeID);
my ($user, $pass) = '';
# Open DB connection
$dsn = "dbi:mysql:database=mp;mysql_read_default_file=$ENV{HOME}/.my.cnf";
$dbh = DBI->connect($dsn, $user, $pass,
{RaiseError=>1, AutoCommit=>0, ShowErrorStatement=>1})
|| die "DB open error: $DBI::errstr";
# Call stored procedure
$sql = "call spCreateTransactionRecord(?, ?)";
$sth = $dbh->prepare($sql);
$sth->bind_param_inout(2, \$p_RecID, 11, {TYPE=>SQL_INTEGER});
$sth->execute($p_TypeID) || print $sth->errstr;
# Disconnects
$dbh->commit();
$dbh->disconnect;
The stored procedures is declared as:
CREATE PROCEDURE spCreateTransactionRecord (
IN p_TypeID INTEGER,
OUT p_RecID INTEGER
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
新代码有一种解决方法:
不太合适(两次数据库调用而不是一次),但可以完成工作。
The new code with a workaround:
Not as proper (two database calls instead of one) but does the job.
这是一个具有“已验证”状态的已知错误,这意味着它从未得到解决。
http://bugs.mysql.com/bug.php?id=23554
该错误报告还包含可能的解决方法。
另一个确认该问题仍未得到解决的消息是 源当前(4.017)版本的代码仍然有错误:
It is a known bug with "Verified" status, meaning it never got addressed.
http://bugs.mysql.com/bug.php?id=23554
That bug reports also contains a possible workaround.
A separate confirmation that the issue is still not addressed is that the source code for the current (4.017) version still has the error: