2

I successfully setup a Drupal 6 site to access external databases and present them in tables via Views.

Now I am trying to move to Drupal 7, and I'm not sure how to troubleshoot. In Drupal6, I can open table wizard after editing the settings.php file; it shows the new tables and I can add them.
Is there a way to know if Drupal 7 can see the database? I edited the settings.php file and created a module that is supposed to describe the database to Drupal 7, but I don't see the tables anywhere.

Any suggestions on how to troubleshoot? I don't get any errors or feedback; it simply doesn't do what I want it to do.

This is my code. I have a file called datamodel.module:

function datamodel_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'datamodel'),
  );
}

I have also a file called datamodel.views.inc. This file is very long but I basically got everything working in drupal6 using table wizards; then I used the table wizards to Views definition for hook_views_data(), which I put in the following code.

function datamodel_views_data() {
  $data = array();
  $data['FundManager'] = array(
    'FundManager' => array(
      'title' => t('FundManager'),
      'help' => t('FundManager.FundManager'),
      'field' => array(
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
        'allow empty' => TRUE,
      ),
      'argument' => array(
        'handler' => 'views_handler_argument_string',
      ),
      'sort' => array(
         'handler' => 'views_handler_sort',
      ),
    ),
    'fundManagerCode' => array(
      'title' => t('fundManagerCode'),
      'help' => t('FundManager.fundManagerCode'),
      'field' => array(
        'handler' => 'views_handler_field_numeric',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_numeric',
        'allow empty' => TRUE,
      ),
      'argument' => array(
        'handler' => 'views_handler_argument_numeric',
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
    ),
    'FundManagerFirm' => array(
      'title' => t('FundManagerFirm'),
      'help' => t('FundManager.FundManagerFirm'),
      'field' => array(
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
        'allow empty' => TRUE,
      ),
      'argument' => array(
        'handler' => 'views_handler_argument_string',
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
    ),
    'FundManagerStartDate' => array(
      'title' => t('FundManagerStartDate'),
      'help' => t('FundManager.FundManagerStartDate'),
      'field' => array(
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
        'allow empty' => TRUE,
      ),
      'argument' => array(
        'handler' => 'views_handler_argument_string',
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
    ),
    'FundManagerDescription' => array(
      'title' => t('FundManagerDescription'),
      'help' => t('FundManager.FundManagerDescription'),
      'field' => array(
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
        'allow empty' => TRUE,
       ),
       'argument' => array(
         'handler' => 'views_handler_argument_string',
       ),
       'sort' => array(
         'handler' => 'views_handler_sort',
       ),
    ),
    'FundCode' => array(
      'title' => t('FundCode'),
      'help' => t('FundManager.FundCode'),
      'field' => array(
        'handler' => 'views_handler_field_numeric',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_numeric',
        'allow empty' => TRUE,
      ),
      'argument' => array(
        'handler' => 'views_handler_argument_numeric',
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
    ),
    'table' => array(
      'group' => t('FundManager'),
    ),
  );

  return $data;
}

I thought I followed the instructions, but nothing happens after I enable the module.

  • you don't see the tables where? Using views? Or are you trying to execute custom queries? Also, show your code... – Berdir May 13 '11 at 6:48
  • Thanks, Berdir. I will. But I was also trying to be more general to learn how to even start troubleshooting. With Java, you get errors when something goes wrong but it seems with drupal there is no error. I'd love to get some kind of feedback from the system on what I'm doing wrong. – Lostsoul May 13 '11 at 7:19
  • Well, that totally depends on what goes wrong. And debugging views and debugging custom module code is quite different, so there isn't much generic things you could do. – Berdir May 13 '11 at 7:22
  • Thanks Berdir. I just posted my code..hopefully that helps with someone helping me. I did notice you were a developer of various modules, may I ask how you troubleshoot packages or your code? Do you code outside of drupal, troubleshoot and then add it as a module or are you creating modules directly? – Lostsoul May 13 '11 at 7:38
1

There are a few things you can do to debug this.

First up try switching the database and doing a general query on your 'fundmanager' table

Something like

 db_set_active('myexternal');
 $result = db_query('SELECT FundCode FROM fundmanager');
 db_set_active('default');

This will test that the database connection is working and visible from drupal.

If that is ok you can put some debug code in your hook_views_data() to make sure that is being called. Clear the cache and go to the list views page.

If both of these are present then it is likely a bug in your tablewizard code. This is a little buggy with external databases. It should define base_database somewhere but there is a bug

|improve this answer|||||
  • Thanks so much Jeremy. I totally get your logic but not sure on the execution of it. How do I create a drupal node with php in it so I can test my code? and If I put debug code in hook_views_data() where would I see it if its only used to enable me access to the views? – Lostsoul May 13 '11 at 8:04
  • Yes, it looks like the base database is missing... – Berdir May 13 '11 at 8:05
  • I remember reading about that..but wasn't sure if it applied to me. I added the database information into the settings.php file. I'll look into the base info and let you know. – Lostsoul May 13 '11 at 8:10
  • You can (for debug code) just put the code inline in your module. Just to see if it runs. hook_views_data is a little more tricky as views aggressively caches the output. put a var_dump('test') in there clear the cache and then go to a views admin page, you should see test in plain text at the top of your page. – Jeremy French May 13 '11 at 8:10
  • Thanks I'll try that. I have been all over drupal.org and have seen quite a few posts from you relating to this matter. Looks like you got it to work using the data module..problem is its not out for drupal7 yet. Its a bit late but tomorrow I'll look at the base database issue and let you guys know the results – Lostsoul May 13 '11 at 8:30
0

Most of the time, when something goes wrong there is an error displayed or logged somewhere depending on your PHP and system setup. Most Linux distributions provide a production safe PHP distribution that disable errors display. For developement, I suggest you enable errors display for PHP and install xdebug to enable stack traces in error messages.

In some rare occasions, Drupal fails to report an error and silently ignore the error. For these cases, tracing execution using Xdebug or the Zend Debugger are the best options. But they may take time to setup.

|improve this answer|||||
  • my site isn't in production yet..so I can enable these and see what it does..drupal has a module that logs errors to a mysql database so I'll check that out also. Thanks for the advice. – Lostsoul May 13 '11 at 8: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.