in reply to Re: insert perl dumper value in mysql
in thread insert perl dumper value in mysql

Thanks for ur reply.. I tried with ur suggestion... but now it shows only the 1st array.. I.e. it displays only..
read', 'eat', 'play
I cant find the other values. \n Also, how can i insert the entire values i.e read eat play in one column. Am able to insert only one value by using for eg one case in which "eat" is inserted into a column
$insert->execute($out[1]);

Replies are listed 'Best First'.
Re^3: insert perl dumper value in mysql
by bellaire (Hermit) on Mar 19, 2009 at 13:30 UTC
    Oops, sorry, I misunderstood. I know that you're trying to insert multiple values, but you can't supply array references to that single insert statement and expect that it's going to insert multiple rows. It's possible to do with one statement, but that involves building a statement which has as many question marks as you have values to pass. It'd be easier to simply loop over the values in your @out array and insert them one at a time.

    For example, with the insert statment you have, something like:
    for my $idx (0..$#{$out->[0]}) { ...prepare your insert statmenet here, inside the loop... $insert->execute($out[0]->[$idx],$out[1]->[$idx],$out[2]->[$idx],$ +out[3]->[$idx]) }
    That'll run many insert statements, but should do what you want (I think!). Note that I'm not passing $out[0] itself, for example, but rather each element as indexed by $idx in turn.
      I tried with ur new solution.. But still its not working.. \n Nothing enters into the table.. and infact when i compile the program it shows error
      Number of rows deleted: 0 Can't use string ("play") as an ARRAY ref while "strict refs" in use a +t ./checkstring.pl line 44. $VAR1 = [ 'read', 'eat', 'play' ];
        Did you undo the changes I asked you to make originally, in the first comment, regarding square brackets? Remember I said that that created an array reference, and this error message is complaining that it wants an array reference.