I'm running Drupal 7 site on WAMP Server!

I'm using below code in a custom block to get data from the database :

$result = db_select('event', 'x')
  ->fields('x', array('address'))
foreach ($result as $value) {
  print_r ($value);

Event is the name of node we use

Every time I try to reload the page, I get this message :

The website encountered an unexpected error. Please try again later.

When I check WAMP PHP error log, there is nothing in it about it !

Any idea ?

Update : Now is see I get this error :

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal.event' doesn't exist: SELECT x.address AS address FROM {event} x; Array ( ) in eval()

I understand that it mean it can't find the table, but why ? I found it like that in every example on the internet !

  • You should look at what database tables are provided for nodes and look at the API for db_select, etc... to see what it actually does.
    – mradcliffe
    Oct 11, 2016 at 13:40
  • That is not how you search in the nodes content. Check this link: drupal.org/node/1343708 Oct 11, 2016 at 13:43
  • @juankvillegas THX, it helped me :)
    – Sinf
    Oct 11, 2016 at 15:32

1 Answer 1


The website encountered an unexpected error. Please try again later.

Above error is Drupal specific error, to get more details about this error you need to go to Drupal Logs. You can access Drupal Logs by navigating to "Admin => Reports => Recent Log Messages". These logs are provided by Database logging Module in Drupal Core.


Event is the name of node we use

In Drupal Nodes data is stored into node table and not table named with content type. Check out getting started guide about node. You've to check node table to get all nodes where type is event.

To fetch nodes you can use EntityFieldQuery API. Check example on How to use EntityFieldQuery. And to fetch any fields value, check Programmatically get field values.

  • Thx for your answer :p
    – Sinf
    Oct 11, 2016 at 13:32
  • I updated my question, may I ask you to have a look please ?
    – Sinf
    Oct 11, 2016 at 13:44
  • @Soheyl, I've updated answer. You're querying into wrong table. To fetch nodes basic data you need to query node table, where nodes basic data such as nid, title, type are stored.
    – Yogesh
    Oct 11, 2016 at 13:59

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.