1

I am trying to write a query: SELECT id, group FROM sdk_country WHERE status = '0' and country_value = 'Afghanistan';

Drupal Query: $query = db_select('sdk_country', 'f'); $query->fields('f', array('id','group')); $query->condition(array( 'f.status', 1, '=', 'f.country_value', 'Afghanistan', '=', )); $result = $query->execute();

not sure what is the issue. Getting the error:

yntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM sdk_country f WHERE (Array IS NULL )' at line 1: SELECT FROM {sdk_country} f WHERE (Array IS NULL ) ; Array ( ) in retreiveEMEAList() (line 458 of C:\Repository\code\beta\sites\all\modules\nhdp_register\nhdp_register.module).

Please help

0

The condition method does not take an array.

https://api.drupal.org/api/drupal/includes%21database%21select.inc/function/SelectQuery%3A%3Acondition/7

You need to separate condition to two calls, one per field, without passing them as an array:

$query->condition('f.status', 1);
$query->condition('f.country_value', 'Afghanistan');
  • Thanks for your quick response... I still get the same error. Can you provide the code please. – Suneel Kumar P Feb 29 '16 at 18:47
  • No luck :( $query = db_select('sdk_country', 'f'); $query->fields('f', array('id','group')); $query->condition('f.status', 1); $query->condition('f.country_value', 'Afghanistan'); $result = $query->execute(); – Suneel Kumar P Feb 29 '16 at 18:57
  • I still get the same error. PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group FROM sdk_country f WHERE (f.status = '1') AND (f.country_value = 'Afghan' at line 1: SELECT f.id AS id, f.group AS group FROM {sdk_country} f WHERE (f.status = :db_condition_placeholder_0) AND (f.country_value = :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => Afghanistan ) – Suneel Kumar P Feb 29 '16 at 19:01
  • $query = db_select('sdk_country', 'f'); $query->fields('f', array('id','group')); $query->condition('f.status', 1); $query->condition('f.country_value', 'Afghanistan'); $result = $query->execute(); – Suneel Kumar P Feb 29 '16 at 19:02
  • Even i have noticed the below code is not working. function retreiveEMEAList($country_value) { $query = db_select('sdk_country', 'f'); $result = $query->execute(); echo '<pre>'; print_r($result); die("1231"); } – Suneel Kumar P Feb 29 '16 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.