php - db_result D6 query conversion to db_select D7 -
i trying convert d6 code query drupal 7
foreach ($order->products $product) { if (db_result(db_query("select nid {the_table} fid = 'string' , nid = %d", $product->nid))) { $nid[] = $product->nid; } }
i changed query:
if (db_result(db_query('select nid {the_table} fid = 'string' , nid = :nid', array(':nid' => $product->nid)))) {
and dynamic query came out written thought
foreach ($order->products $product) { $query = db_select('{the_table}', ''); $query->fields('nid', array('')); $query->condition('fid', 'string'); $query->condition('nid', ':nid'); $query->execute(); $result = $query->fetchassoc(); foreach ($result $record) { $product->nid; $nid [] = $product->nid; } }
i tried "->fetchfield();" statement in there instead - same error tried :string instead of 'string'
it throws error
pdoexception: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'as the_table the_table (fid = 'string') and' @ line 1: select nid. {the_table} the_table (fid = :db_condition_placeholder_0) , (nid = :db_condition_placeholder_1) ; array ( [:db_condition_placeholder_0] => string [:db_condition_placeholder_1] => :nid ) in process() (line 450 of /. . . the.module).
also not know why error shows 2 of "the_table" - 1 behind - possible otrignal d6 query bad ??
does know have done wrong ??
i did not pay close enough attention brackets not proper syntax in new format of query. works - , see other places went wrong after reading dynamic query page again @ https://www.drupal.org/dynamic-queries
<?php $query = db_select('the_table', 'the_table'); $query->fields('the_table', array('nid')); $query->condition('the_table.fid', 'string'); $query->condition('the_table.nid', $product->nid); $query->execute(); ?>
Comments
Post a Comment