Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: MySQL INSERT in Perl

by NetWallah (Canon)
on Aug 04, 2011 at 17:46 UTC ( [id://918605]=note: print w/replies, xml ) Need Help??


in reply to Re^2: MySQL INSERT in Perl
in thread MySQL INSERT in Perl

OK - strict, did identify your problem, which does indeed show a scoping issue.

Do you have BLOCKS in your code - i.e - segments of code enclosed in {curly braces} ?

Is the "my $ins_rec" line inside one of these blocks ?
If so, that variable is not visible outside the block - you need to move the "my" statement outside the block.

Please do yourself a favour and ALWAYS "use strict;" and "use warnings;". Professional programmers recommend this for very good reasons.

            "XML is like violence: if it doesn't solve your problem, use more."

Replies are listed 'Best First'.
Re^4: MySQL INSERT in Perl
by baperl (Sexton) on Aug 04, 2011 at 17:55 UTC
    it was indeed a scoping problem...I fixed it. it runs and it inserts records into the database, but it gives a new error now:
    DBD::mysql::db do failed: Unknown column 'N' in 'field list' at otest. +pl line 52.
    I am perplexed...it says do failed, but it did insert the records and it does it all correctly...then why the error? this is my updated code:
    my $dbh=DBI->connect($dsn,$user,$pwd); foreach my $hr1 (@calls) { my %h1 = %{$hr1}; next unless defined $h1{'symbol'}; my $ins_rec="INSERT INTO $table (symbol,valuation_dt,expn_dt,strik +e,open,bid,ask,last,volume) VALUES(\'$h1{'symbol'}\',now(),\'$exp\',$ +h1{'strike'},$h1{'open'},$h1{'bid'},$h1{'ask'},$h1{'last'},$h1{'volum +e'});"; print "my ins_rec is $ins_rec\n"; my $sth=$dbh->do($ins_rec); }

      Stop pasting values into your SQL. Use placeholders. Now!

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-24 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found