专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Perl/Python

新手请问关于数据库模块开发时Execute遇到的传参数有关问题

发布时间:2011-06-29 20:10:40 文章来源:www.iduyao.cn 采编人员:星星草
新手请教关于数据库模块开发时Execute遇到的传参数问题。
请教下关于模块传参数问题:
以下是我写的一个模块,但是在调用execute时发生了错误:

DBD::mysql::st execute failed: called with 1 bind variables when 2 are needed .....
cannot execute sql called with 1 bind variables when 2 are needed .....

使用splice(@_,0,1);是因为每次传过来的参数都带有DBD::mysql::这个,请问下各位还有其他方法获取传过来的参数吗?
下面的execute,$_ 已经处理过了,并且参数正确,但依然报错。

谢谢各位了。

Perl code

#!/usr/bin/perl

package DBD::MYSQL;
use DBI;

my $db = "dbdb";
my $db_user = "root";
my $db_pass = "";
my $db_server = "localhost";
my $dbh = undef;
my $sth = undef;
my @ResultS;

sub new{
    $db = $_[0] || $db;
    $db_user = $_[1] || $db_user;
    $db_pass = $_[2] || $db_pass;
    $db_server = $_[3] || $db_server;
}
sub InitDB{
    print "Init DBConnection...\n";
    $dbh = DBI->connect("dbi:mysql:$db:$db_server",$db_user,$db_pass) or die("could not connect to DBServer...\n");
    print "DBConnection Inited...\n";
}

sub closeDB(){
    $sth->finish;
    $dbh->disconnect;
}

sub prepare{
    splice(@_,0,1);
    $sth = $dbh->prepare($_[0]);
}

sub execute{
    splice(@_,0,1);
    $sth->execute($_) or die("cannot execute sql " . $sth->errstr);
}

sub nextRecord{
    @ResultS = $sth->fetchrow_array();
}

1;
__END__



------解决方案--------------------
在代码里把execute的参数打出来,然后贴出来看下。没有什么东西会如你所说一定“正确”。如果你认为正确的就正确,你就不会来提问了。所以即使你认为正确的信息,也贴出来看下,让别人相信是正确的。
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: