我想查詢到我的數據庫,但由於某些原因,當我進入硬編碼的參數查詢唯一的工作。如果我使用的變量,查詢拒絕工作......MySQL查詢無法處理變量
這是我的查詢與硬編碼參數和工作得很好:
$q_jobs = 'select distinct nid from node n, field_data_field_job_tags as tags
where (type= \'job\' and n.language = \'nl\' and tags.entity_id = n.nid
and tags.field_job_tags_value = \'Enterprise Asset Management\')
order by n.changed desc limit 7';
但是當我使用的變量,查詢拒絕工作.. 。
$q_jobs = 'select distinct nid from node n, field_data_field_job_tags as tags
where (type= \'job\' and n.language = :lang and tags.entity_id = n.nid
and tags.field_job_tags_value = :title)
order by n.changed desc limit 7';
$results_jobs = db_query($q_jobs, array(':lang' => $language->language,
':title' => $node->title));
雖然是Drupal查詢,但我認爲這只是我的語法中某處的錯誤?
我得到這個錯誤:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(type= 'job' and n.language = 'nl' and tags.entity_id = n.nid and tags.field_job' at line 1: select distinct nid from {node} n, field_data_field_job_tags as tagswhere (type= 'job' and n.language = :lang and tags.entity_id = n.nid and tags.field_job_tags_value = :title)order by n.changed desc limit 7; Array ([:lang] => nl [:title] => Enterprise Asset Management) in rd_get_related_news_and_blogs()
你得到任何類型的錯誤? –
是的,我將它添加到我的問題 – Michiel
類型屬於哪個表?所有其他字段名稱都以tablename.filed名稱的形式給出,在caluse – ray