Here is my PDO request :
$query = db_select('review_ratings_table')
->fields('review_ratings_table',array('review_nid'))
->condition('loc_id', $loc_id, 'LIKE')
->condition('user_id', $user_id, 'LIKE')
->condition('valid', '1', '=')
->execute();
while($record = $query->fetchAssoc()) {
drupal_set_message('<pre>test '.print_r($record).'</pre>');
}
I have tried many ways to get the result of this request (fetchAll, fetchField, fetchAssoc ...) and I keep printing "1" instead of the review_nid or anything else.
Thanks for you help.
Will
=> Hi, If I use dvm($query) I get that :
DatabaseStatementBase::__set_state(array( 'dbh' => DatabaseConnection_mysql::__set_state(array( 'needsCleanup' => false, 'target' => 'default', 'key' => 'default', 'logger' => NULL, 'transactionLayers' => array ( 'drupal_transaction' => 'drupal_transaction', ), 'driverClasses' => array ( 'SelectQuery' => 'SelectQuery', 'DatabaseTransaction' => 'DatabaseTransaction', ), 'statementClass' => 'DatabaseStatementBase', 'transactionSupport' => true, 'transactionalDDLSupport' => false, 'temporaryNameIndex' => 0, 'connectionOptions' => array ( 'database' => '*******', 'username' => '*******', 'password' => '*******', 'host' => 'localhost', 'port' => '3306', 'driver' => 'mysql', 'prefix' => array ( 'default' => '', ), ), 'schema' => NULL, 'prefixes' => array ( 'default' => '', ), 'prefixSearch' => array ( 0 => '{', 1 => '}', ), 'prefixReplace' => array ( 0 => '', 1 => '', ), )), 'queryString' => 'SELECT review_ratings_table.review_nid AS review_nid FROM review_ratings_table review_ratings_table WHERE (loc_id LIKE :db_condition_placeholder_0 ESCAPE \'\\\') AND (user_id = :db_condition_placeholder_1) AND (valid = :db_condition_placeholder_2) ', ))
and
Error message Recoverable fatal error: Object of class DatabaseStatementBase could not be converted to string in review_ratings_table_node_presave() (line 52 of C:\Bitnami\drupal-7\apps\drupal\htdocs\sites\all\modules\custom\review_ratings_table\review_ratings_table.module).
and
dvm($query->fetchAssoc()); gives me that
array( 'review_nid' => '2', )
Which is what I want but I don't know how to access it.
Thanks
$loc_id
and$user_id
, and why are you usingLIKE
for (what I assume is) a numeric field? It'd be a good idea to try your query in raw SQL first to make sure that logic is sounddvm($query);
anddvm($query->fetchAssoc());
? If it doesn't show anything then try withvar_dump()
also...$result = $query->fetchAssoc(); return $result[0]['review_nid'];