It's hard to find the error because your code is all on one line, but it looks like the problem is that your URL isn't quoted. That must be the problem.

Using placeholders might make it easier for you to code if you are using a loop to execute the statements, but it might not give you a performance benefit in MySQL. MySQL doesn't support server-side prepared statements by default and I think that's where the performance benefit comes in with placeholders and bind values. I've had some problems with turning on this setting on, but try it if you want to experiment with it. ref: DBD::mysql (search for "prepared").

Columns with character data types will need quotes. You can quote everything, though because it won't break anything with the other data types.

MySQL will tell you what's wrong if you set up your queries properly. Break it back out to more lines during troubleshooting, then condense it again when everything works.

Here's my suggested method:

use strict; use warnings; my $connect_string = "DBI:mysql:$CONFIG::database"; my $dbh = DBI->connect( $connect_string, $CONFIG::dbusername, $CONFIG::dbpassword, \%CONFIG::dbattr ); my $statement; my $result; { package CONFIG; %dbattr = ( PrintError => 0, ChopBlanks => 0, ); $database = "stuff"; $dbusername = "username"; $dbpassword = "password"; } my $insert = qq{ INSERT INTO storage ( url, altavista, yahoo, msn, teoma, google, alltheweb, Total, lastsearch, totalsearch ) values( '$url', '$altavista_results', '$yahoo_results', '$msn_results', '$teoma_results', '$google_results', '$alltheweb_results', '$total', '$time', '$total' ) }; my $update = qq{ UPDATE storage SET url = "$url", altavista = "$altavista_results", yahoo = "$yahoo_results", msn = "$msn_results", teoma = "$teoma_results", google = "$google_results", alltheweb = "$alltheweb_results", total = total +1, time = "$time" }; $statement = $update; $result = $dbh->do( $statement ); if ( ! defined $result ) { die "Fatal SQL error :\n$statement\n" . $dbh->errstr; } # If there were no rows affected by the update, execute the # insert if ( $result < 1 ) { $statement = $insert; $result = $dbh->do( $statement ); if ( ! defined $result ) { die "Fatal SQL error :\n$statement\n" . $dbh->errstr; } }
--
-- GhodMode

In reply to Re: Mysql error near values( by GhodMode
in thread Mysql error near values( by coldfingertips

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.