After hours of testing different options I cannot find how to simply make a PHP code argument work in D7:
$result = db_query('SELECT entity_id FROM dr_field_data_field_departement WHERE field_departement_tid=4');
return $result;
this one returns: Object of class DatabaseStatementBase could not be converted to string in DatabaseStatementBase->execute() (line 2039

$result = db_query('SELECT entity_id FROM dr_field_data_field_departement WHERE field_departement_tid="4"');
return $result;
this one gets: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '4' in 'where clause': SELECT entity_id FROM dr_field_data_field_departement WHERE field_departement_tid="4"; Array
(
)
in eval() (line 1

An idea?

Comments

dawehner’s picture

Component: node data » Miscellaneous
Category: bug » support
Priority: Major » Normal
Status: Active » Fixed

Your php code is a major bug, this is obvious :)

What about this:

$result = db_query('SELECT entity_id FROM {dr_field_data_field_departement} WHERE field_departement_tid = :tid', array(':tid' => 4))->fetchField();

For more informations about the dbtng syntax have a look at http://drupal.org/node/310072

zanoman’s picture

man, thanks!
it looks weird to me but works perfectly, brilliant!
I'm the bug in this story :)
Have a very nice day

zanoman’s picture

how to get more than one result?

zanoman’s picture

fetchAll throws:
Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2039

zanoman’s picture

Status: Fixed » Active
dawehner’s picture

Status: Active » Fixed

Please be fair. There are thousand of other places to get help for dbtng:

* the forum
* IRC
* ...
* payed support etc.

Please read http://drupal.org/node/310072

$result = db_query('SELECT entity_id FROM {dr_field_data_field_departement} WHERE field_departement_tid = :tid', array(':tid' => 4))->fetchAll();
zanoman’s picture

Ok, thanks again Dereine.
It's very kind of you for pointing me to this valuable post.
Cheers

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.