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;
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.