I have a need to display views using an old Drupal database. These views are already created, so I exported them and dropped the export code into a custom module hook_views_default_view, put in the necessary return, changed the view name, updated the paths, etc. So, now I have two Views showing exactly the same dataset.

I need the newly created one to query against an old database; both databases have exactly the same structure. I have the old database setup in settings.php and, I thought, all I needed to do was add $view->database = "oldlife". That's not working - I'm getting the exact same data in both views (two different paths).

This is the code, minus all the handlers and unnecessary stuff:

function lwg_old_db_views_api() {
    return array(
            'api' => 3,
            'path' => drupal_get_path('module', 'lwg_old_db'),

function lwg_old_db_views_default_views() {
    $view = new view();
    $view->name = 'commerce_vbo_views_orders_oldlife';
    $view->description = 'Display a list of orders for the store admin.';
    $view->tag = 'commerce';
    $view->database = 'oldlife';
    $view->base_table = 'commerce_order';
    $view->human_name = 'Orders';
    $view->core = 0;
    $view->api_version = '3.0';
    $view->disabled = FALSE; 
      * many lines of $handler-> stuff
    $handler = $view->new_display('page', 'Page', 'page_1');
   $handler->display->display_options['path'] = 'list-all-nodes';
   $views[$view->name] = $view;
   return $views;
  • interesting question, pretty clueless on an answer. are you sure $view->database is used everywhere within the view when processing queries? Do oldlife and olddb need to match? – tenken Nov 26 '14 at 18:51
  • I'm not sure @tenken. Matter of fact, I can't even find what led me to believe $view->database was even a thing, I'm digging through the API now. oldlife is the correct name of the database connection in settings.php, I was wrong in the question text, I'll edit it now. – Chris Rockwell Nov 26 '14 at 19:29

Have a look at this module, it can do the job for you.


|improve this answer|||||

It's $view->base_database, not $view->database.

|improve this answer|||||

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.