请教下关于模块传参数问题:
以下是我写的一个模块,但是在调用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的参数打出来,然后贴出来看下。没有什么东西会如你所说一定“正确”。如果你认为正确的就正确,你就不会来提问了。所以即使你认为正确的信息,也贴出来看下,让别人相信是正确的。