我正在尝试查询我的数据库,但由于某种原因,查询仅在我输入硬编码的参数时才有效。如果我使用变量,查询拒绝工作......
这是我的带有硬编码参数的查询,并且工作得很好:
$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]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '(type= 'job' and n.language = 'nl' and tags.entity_id = n.nid and tags.field_job' 附近使用正确的语法:选择与 {node} n 不同的 nid,field_data_field_job_tags 作为 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] => 企业资产管理 ) 在 rd_get_related_news_and_blogs()