RE: Fetch without Execute...
From: Scott V Nipp (sn4265_at_sbc.com)
Date: 10/14/03
- Next message: Unknown Sender: "Re: DBD::XBase not finding tables"
- Previous message: Ronald J Kimball: "Re: Fetch without Execute..."
- Maybe in reply to: Scott V Nipp: "Fetch without Execute..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: Ronald J Kimball <rjk-dbi@focalex.com> Date: Tue, 14 Oct 2003 08:35:32 -0500
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: sn4265@sbc.com
Web: http:\\ldsa.sbcld.sbc.com
-----Original Message-----
From: Ronald J Kimball [mailto:rjk-dbi@focalex.com]
Sent: Tuesday, October 14, 2003 8:25 AM
To: NIPP, SCOTT V (SBCSI)
Cc: dbi-users@perl.org
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
- Next message: Unknown Sender: "Re: DBD::XBase not finding tables"
- Previous message: Ronald J Kimball: "Re: Fetch without Execute..."
- Maybe in reply to: Scott V Nipp: "Fetch without Execute..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|