Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Use of uninitialized value in join or string

by hippo (Curate)
on Jan 29, 2014 at 13:20 UTC ( #1072506=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Use of uninitialized value in join or string
in thread Use of uninitialized value in join or string

Your code snippet here isn't actually using placeholders, so you may not have quite grasped what they are. See how roboticus is using the question marks in his SQL? See how he calls execute with the field list? These are things which you should be doing.


Comment on Re^3: Use of uninitialized value in join or string
Download Code
Re^4: Use of uninitialized value in join or string
by domaniqs (Initiate) on Jan 29, 2014 at 13:36 UTC

    Thank you hippo for pointing this out, however, the snippet I've inserted into my recent post, is the piece of code, that was removed and replaced by the code, that roboticus kindly suggested to me in his post.

    So instead of:

    my $SQL = "INSERT INTO $table VALUES (" . join(",", map { "?" } $csv->fields) . ")"; $prep = $db->prepare($SQL) or die "..."; while (my $row = $csv->getline($fh)) { $prep->execute($csv->fields); }

    I used:

    my $SQL = "INSERT INTO $table VALUES (" . join(",", map { "?" } $csv->fields) . ")"; $prep = $db->prepare($SQL) or die "Cannot prepare database"; while (my $row = $csv->getline($fh)) { $prep->execute($csv->fields); }

    It does not change the fact, that I still struggle with this new error:

    DBD::mysql::st execute failed: Column count doesn't match value count at row 1 at ./test.pl line 85, <$fh> line 2.

      Sorry, I misread your post. Your placeholders there look OK at first pass.

      So, for starters I would use @$row as the argument to execute and then I would compare the number of fields in $row with the number of fields in your database for $table and see where the mismatch occurs. HTH.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1072506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2014-10-30 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (206 votes), past polls