PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column I am tring to perform the following sql query to check if the name that was inserted to the form already created as taxonomy name. But I keep getting this error message:


  PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'test' in 'where clause': SELECT COUNT(*) FROM {taxonomy_term_data} WHERE name = test; Array ( ) in get_google_map_api() (line 79 of /Applications/MAMP/htdocs/Drupal/sites/all/modules/toodate/toodate.module).


my function is:

function get_google_map_api($item){
    $city_name = $item;
    $chack_if_is_taxonomy = (db_query("SELECT COUNT(*) FROM {taxonomy_term_data} WHERE name = ".$city_name));       
    var_dump($chack_if_is_taxonomy);
    drupal_exit();
}
Quick fix would be adding the missing single quotes around your variable. Forgetting the quotes can throw odd errors from this function, such as mixing a string for a column, like in your case.

There are less error prone ways to make short queries like this. See also Molot's answer.