新手请教关于数据库模块开发时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,$_ 已经处理过了,并且参数正确,但依然报错。
谢谢各位了。
#!/usr/bin/perlpackage 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__