what's wrong with this MySQL prepared statement? "unkown column in where clause"
I'm using a prepared statement with this SQL code:
SELECT `name` FROM `securities` WHERE `symbol`=? AND `type`=`C`
but I keep getting this error when I execute it:
Column not found: 1054 Unknown column 'C' in 'where clause'
The table is set up like this:
+--------+-----------------------+------+------+
| symbol | name | type | used |
+--------+-----------------------+------+------+
| AED | UAE Dirham | C | 0 |
| ALL | Albanian Lek | C | 0 |
| ANG | Neth Antilles Guilder | C | 0 |
| ARS | Argentine Peso | C | 0 |
| AUD | Australian Dollar | C | 0 |
| AWG | Aruba Florin | C | 0 |
| BBD | Barbados Dollar | C | 0 |
| BDT | Bangladesh Taka | C | 0 |
| BGN | Bulgarian Lev | C | 0 |
| BH开发者_如何转开发D | Bahraini Dinar | C | 0 |
+--------+-----------------------+------+------+
and I'm trying to query just the name from it. How can I fix this error? The code that involves binding a value is too long to post, but basically, it executes the prepared statement with array($symbol)
. Is there an SQL error that I'm missing?
You have the value C
enclosed in backticks. This should only be done for column and table names, not values.
Change it to quotes and it should work:
SELECT `name` FROM `securities` WHERE `symbol`=? AND `type`='C'
things in backticks are assumed to be column/table names in MySQL. What your asking MySQL to do there is return all the rows where the value in the type column is the same as is in the C column, what you actually wanted was a single (or double) quote. ie.
SELECT `name` FROM `securities` WHERE `symbol`=? AND `type`='C'
精彩评论