dthacker has asked for the wisdom of the Perl Monks concerning the following question:
I've been away from perl for too long, and I'm missing something silly.
I have a series of text files that I'm reading and
changing each line to pipe-delimited
writing to a new file
inserting into a database table
The pipe de-limiting and writing to a separate file are going fine. But I'm missing something critical on the insert. I'm using an example from gmax's DBI Recipe Tutorial. After I read in the record, I pipe-delimit it and then split it into an array. I then attempt to insert the array into the database, where things go badly. Code and error messages are below.
Resulting Errors:
and so on.......
Dave
Code On!
The pipe de-limiting and writing to a separate file are going fine. But I'm missing something critical on the insert. I'm using an example from gmax's DBI Recipe Tutorial. After I read in the record, I pipe-delimit it and then split it into an array. I then attempt to insert the array into the database, where things go badly. Code and error messages are below.
#!/usr/bin/perl use strict; use DBI; #configurables my $workdir = "./work"; my $roster = ""; my $dbh = DBI->connect("DBI:mysql:database=esms", 'username', 'password', ) or die "Can't connect to database"; my @fields = qw (player_name player_age player_nat player_prs player_s +t player_tk player_ps player_sh player_stamina player_aggression player_kab player_tab player_pab player_sab player_games player_sav player_ktk player_ +kps player_sht player_gls player_dpoints player_inj playe +r_sus player_fit); my $fieldlist = join ", ", @fields; my $field_placeholders = join ", ", map {'?'} @fields; my $insert_query = qq{ INSERT INTO employees ( $fieldlist ) VALUES ( $field_placeholders )}; my $sth= $dbh->prepare( $insert_query ); opendir DIR, $workdir; @files = grep /ja/, readdir DIR; closedir DIR; foreach (@files) { $roster = $_; print"now processing $roster\n"; open (RF,"./work/$roster"); open (UNL,">./work/$roster.unl"); while (<RF>) { chomp; next if m/^Name/; next if m/----/; print "$_\n"; $_ =~ s/\s+/|/g; my @player_rec = split '|'; if ($sth->execute(@player_rec)) { print "Worked, cool"; } else { print "Didn't work, uncool, error is: $DBI::errstr"; } print UNL "$_\n"; } close(RF); close(UNL); }
Didn't work, uncool, error is: called with 71 bind variables when 24 a +re neededZ_Otyusyo|24|ire|R|3|5|11|5|55|21|300|300|300|300|0|0|0|0|0| +0|0|0|0|0|100| DBD::mysql::st execute failed: called with 74 bind variables when 24 a +re needed at ./planb.pl line 45, <RF> line 17. Didn't work, uncool, error is: called with 74 bind variables when 24 a +re neededP_Choonduaga|25|cam|R|3|7|10|7|57|35|300|300|300|300|0|0|0|0 +|0|0|0|0|0|0|100| DBD::mysql::st execute failed: called with 77 bind variables when 24 a +re needed at ./planb.pl line 45, <RF> line 18. Didn't work, uncool, error is: called with 77 bind variables when 24 a +re neededV_Itroidro|19|ita|LC|3|5|10|7|42|24|300|300|300|300|0|0|0|0| +0|0|0|0|0|0|100| DBD::mysql::st execute failed: called with 76 bind variables when 24 a +re needed at ./planb.pl line 45, <RF> line 19. Didn't work, uncool, error is: called with 76 bind variables when 24 a +re neededK_Ogoejheb|23|jap|C|3|9|9|8|45|28|300|300|300|300|0|0|0|0|0| +0|0|0|0|0|100|
Janitored by holli - added readmore tags
Edit. Fixed Tutorial Link dthacker
Dave
Code On!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBI reports too many bind variables
by davidrw (Prior) on May 24, 2005 at 17:52 UTC | |
by Juerd (Abbot) on May 24, 2005 at 17:55 UTC | |
by davidrw (Prior) on May 24, 2005 at 18:06 UTC | |
Re: DBI reports too many bind variables
by Juerd (Abbot) on May 24, 2005 at 17:47 UTC | |
by davidrw (Prior) on May 24, 2005 at 18:00 UTC | |
Re: DBI reports too many bind variables
by injunjoel (Priest) on May 24, 2005 at 17:53 UTC | |
Re: DBI reports too many bind variables
by dbwiz (Curate) on May 24, 2005 at 20:29 UTC | |
Re: DBI reports too many bind variables
by dthacker (Deacon) on May 24, 2005 at 18:04 UTC |
Back to
Seekers of Perl Wisdom