Magento 1.9 – Fix Direct SQL Query Error: Column Not Found

databasemagento-1.9

I have a table with content:
enter image description here

I want to write a direct SQL query to select the time_delivery, where country is, for example, DK in this case.
So it should return 1-5.

I was following a tutorial: https://fishpig.co.uk/magento/tutorials/direct-sql-queries/
And tried modifying query myself like this:

$country= "DK";
$query = 'SELECT time_delivery FROM ' . $table . ' WHERE country = '
     .$country . ' LIMIT 1';

But I get an error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'DK' in 'where clause'

I would assume that it has something to do with the fact the in the tutorial he uses an int but I want to use a string

Best Answer

try this way

$country= "DK";
$query = 'SELECT time_delivery FROM ' . $table . ' WHERE country ="'.$country.'" LIMIT 1';
Related Topic