Where子句中的PHP变量字符串为空

时间:2017-02-03 16:24:26

标签: php mysql drupal

echo "row->name = '$row->name'"; //prints name correctly

我的字段名称

$next_row = db_query("select * from field_data_field_department d join taxonomy_term_data t on d.field_department_tid = t.tid where d.entity_id = $entityID and t.name = '$row->name'");

返回未找到的列:1054未知列'我的字段名称'在where子句''

如果我在MariaDB中运行查询,那么

select * from field_data_field_department d join taxonomy_term_data t on d.field_department_tid = t.tid where d.entity_id = 10568 and t.name = 'Name of my field';

1 个答案:

答案 0 :(得分:0)

可能与您访问对象的事实有关

(一定要避免sql注入)并尝试使用concat

  $next_row = db_query("select * 
          from field_data_field_department d 
          join taxonomy_term_data t on d.field_department_tid = t.tid 
          where d.entity_id = $entityID and t.name = '" . $row->name ."'");