0

So I want to write the following query in PHP using PHP but I am wasting a ton of time trying to figure out something that should be simple.

Query in SQL

SELECT * 
FROM `table_name`
WHERE `column1` = 0560 

Now it has to be exactly that way, the values can't have ' ', or " ", or even back ticks around them. I tried it with those around the values and it just keeps failing even in SQL if its not exactly like the above.

Now I have tried the following, but none of which are successful and it's annoying me to no end

$a_query = "SELECT * FROM `".$table_name."` WHERE `".$column_name."` = `".$store_num."`";
$a_query = "SELECT * FROM `table_name` WHERE `column1` = `0560`";

I know I've tried a few other variations I just can't recall them right now. I've been at this for a while this evening.

Anyways I get this error every time

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0560' in 'where clause'

Thanks for the help, I realize I'm probably missing something simple, my eyes are just fried

4

1 回答 1

3

字符串文字应该用单引号括起来'

反引号`用于包围标识符(列名、表名、别名等)

双引号"行为取决于通讯员sql_mode

于 2013-06-28T00:12:10.160 回答