1

I am using the following code, but it throws an error.

$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();

The error I get is the following.

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 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).

How can I fix this error?

1 Answer 1

0

condition() doesn't take an array as argument.

You need to replace $query->condition(array('f.status', 1, '=', 'f.country_value', 'Afghanistan', '=')); with the following lines.

// The third argument isn't necessary as `=` is the dafault operator, in this case.
$query->condition('f.status', 1);
$query->condition('f.country_value', 'Afghanistan');

The query is using the value of the status field, but that isn't added to the list of fields passed to $query->fields().
group is a reserved word in MySQL 5.5; it cannot be used as identifier for a table field.

1
  • Thanks for your quick response... I still get the same error. Can you provide the code please. Feb 29, 2016 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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