i_me_mine
i_me_mine

Reputation: 1433

write query correctly php pdo

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

Upvotes: 0

Views: 49

Answers (1)

zerkms
zerkms

Reputation: 254886

String literals should be enclosed in a single quotes '

Backticks ` are used to enclose identifiers (column name, table name, alias, etc)

Double quotes " behaviour depends on a correspondent sql_mode

Upvotes: 3

Related Questions