Good morning all,
I'm getting this error "DBD::mysql::st execute failed: called with one bind variables when 4 are needed at prog line 87, CSV2 line 17. Here is the code as it stands...
#!/usr/bin/perl -w # # use strict; use DBI qw(:sql_types); #### # Set global dbase connection info # # #### my $dsn="dbi:mysql:database=sfiemsmerc"; my $user="root"; my $passwd=""; my $dbh = DBI->connect($dsn, $user, $passwd, { RaiseError =>1, PrintEr +ror => 1, AutoCommit => 0 }); $dbh->trace(1); my @files = <*.dump>; foreach my $file (@files) { my $table = "$file"; $table =~ s/\.dump//g; #### # Delete current data from hobby table # Separate connection!! # #### my $delete00 = $dbh->prepare("DELETE FROM $table"); $delete00->execute(); $dbh->commit(); #### # create and prepare insert connection and action # call q_marks to insert "?" into $stmnt # # #### $dbh = DBI->connect($dsn, $user, $passwd, { RaiseError => 1, PrintErro +r => 1, AutoCommit => 0 }); $dbh->trace(1); my $csvfile="$file"; open (CSV2,"$csvfile")|| die "Cannot open $csvfile, $!"; while (<CSV2>) { chomp; if ( /rows$|^$table/ ) { next; }else{ s/'//g; my (@data) = split /,/; chomp @data; my $stmnt = "INSERT INTO $table VALUES ()"; $stmnt = q_marks($stmnt,\@data); my $insert00 = $dbh->prepare("$stmnt"); my $count = @data; my @values; for (my $i = 0;$i <= $count - 1;++$i) { my $word = "$data[$i]"; unshift(@values,$word); } $count = @values; if (! $count ) { next; }else{ my $values = join(',',reverse(@values)); chomp $values; #print "$values\n"; $insert00->execute("$values"); } } #### # Close and commit dbase changes # # #### close CSV2|| die "Cannot close $csvfile, $!"; $dbh->commit(); $dbh->disconnect(); } #### # # #### #unlink $csvfile|| die "Cannot remove $csvfile, $!"; #unlink $csv2file|| die "Cannot remove $csv2file, $!"; } my $date = localtime time; print "$date:hobby_update:Update Complete\n"; sub q_marks { my($stmnt,$data) =@_; my @marks; foreach (@$data) { unshift(@marks,"?"); } my $line = join(',',@marks); $stmnt =~ s/(\()(\))/$1$line$2/; return $stmnt; }
There are four data fields that need to be inserted. The data files are comma-delimited, one row per line, "'" qualified. I'm stripping the "'" qualifier. Do I need to bind_param the fields? If so, what would be a good way to do that? Any suggestions anyone has would be greatly appreciated. Thanks, Dalin Where ever there is confusion to be had... I'll be there.

Edit kudra, 2002-04-16 Added readmore


In reply to DBI:mysql by Dalin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.