Cocest
Cocest

Reputation: 146

Error, using multiple WHERE in mysql

I'm having error trying to access mysql data, using multiple WHERE clause in preparedstatement. This is the code that generate sql exception( parameter index out of range ( 2 > number of parameters, which is 1 );

"SELECT Arrived_time, Closed_time FROM ? 
WHERE (\"Year  = ?\n) AND (\"Month = ?\n) AND (\"Day = ?)" 

and I entered the three paremeters. Is there a better way?

Upvotes: 0

Views: 116

Answers (2)

Ilion
Ilion

Reputation: 6882

As mentioned, you need to specify your table name and use correct quoting:

"SELECT `Arrived_time`, `Closed_time` FROM TABLENAME
WHERE (`Year`  = ?) AND (`Month` = ?) AND (`Day` = ?)" 

Upvotes: 1

IMSoP
IMSoP

Reputation: 97908

You are missing the closing quotes when naming the columns "Year", "Month", and "Day":

"SELECT Arrived_time, Closed_time FROM ? 
WHERE (\"Year\"  = ?\n) AND (\"Month\" = ?\n) AND (\"Day\" = ?)" 

In your version, the database will be looking for a column called something like "Year = ?\n) AND ("

Upvotes: 0

Related Questions