Thanks for the feedback.  Your guess about 'key' being a MySQL
reserved word was correct.  Now to take a stab at the next error, and do a
little reading on placeholders.  Thanks again.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-----Original Message-----
From: Ronald J Kimball [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 14, 2003 8:25 AM
To: NIPP, SCOTT V (SBCSI)
Cc: [EMAIL PROTECTED]
Subject: Re: Fetch without Execute...


On Tue, Oct 14, 2003 at 08:06:30AM -0500, NIPP, SCOTT V (SBCSI) wrote:
>       I have run into this problem before, but unfortunately, I can't seem
> to figure out what I am doing wrong again this time...  I am working on a
> script to parse a data file and INSERT/UPDATE this data into a MySQL
> database table.  I am able to verify that the data I am dealing with is
what
> I expect, and the simple logic in the script is performing as desired.
The
> problem I am running into at the moment is the following pair of error
> messages:
> 
> DBD::mysql::st execute failed: You have an error in your SQL syntax near
> 'key ='
> 1281-02F'' at line 1 at ./emc_data2.pl line 35, <FILE> line 134.
> DBD::mysql::st fetch failed: fetch() without execute() at ./emc_data2.pl
> line 36
> , <FILE> line 134.

You're focusing on the wrong error message.  The "fetch without error"
occurs because the execute failed.  If you fix the execute, the fetch will
work also.

The execute fails because there's a syntax error in the SQL, as the first
message says.  You should print out the constructed SQL statement and make
sure it's valid.  Without seeing the entire statement, I'm not sure what
the syntax error is.  Is key a reserved word in MySQL?


>     while ($data = <FILE>) {
>       @fields = split(/\s+/, $data);      
>       my $chk = $dbh->prepare("SELECT * FROM emc_usage WHERE key
> ='$fields[5]'");

Also, you should be using placeholders, or at least DBI->quote(), instead
of interpolating external data directly into an SQL statement.


Ronald

Reply via email to