hi, I am trying to run an INSERT command from Perl, and encounter the following error:
DBD::mysql::st execute failed: Query was empty at otest.pl line 56. SQL error:$DBI::errstr
so, I wrote a print command to see the output on my screen and that produces the results fine. here's the print and the insert command....I suspect I might not be using the right syntax in my INSERT command....can you please help me fix it/point me in the right direction...thx!
print "Symbol: $h1{'symbol'}\tExpn_date: $exp\tStrike: $h1{'strike'}\t +Bid: $h1{'bid'}\tAsk: $h1{'ask'}\tLast: $h1{'last'}\tOpen: $h1{'open' +}\tVolume: $h1{'volume'}\n "; my $ins_rec="INSERT INTO $table (symbol,expn_dt,strike,open,bid,ask,la +st,volume) VALUES(\'$h1{'symbol'}\',\'$exp\',\'$h1{'strike'}\',\'$h1{ +'open'}\',\'$h1{'bid'}\',\'$h1{'ask'}\',\'$h1{'last'}\',\'$h1{'volume +'}\');";
Thank you for your replies. Dave, I did use DBI
my $dbh=DBI->connect($dsn,$user,$pwd) || die "could not connect to dat +abase:$error\n";
NetWallah,this is the code for the INSERT string being applied to the database.
my $sth=$dbh->prepare($ins_rec); $sth->execute || die "SQL error:$error\n";
When I print $ins_rec, I get a blank... <code> my ins_rec is DBD::mysql::st execute failed: Query was empty at otest.pl line 57. SQL error:$DBI::errstr <code>

In reply to MySQL INSERT in Perl by baperl

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.