Answers.Body: <p>You can use the data processor extension (<a href="https://lab.civicrm.org/extensions/dataprocessor" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/dataprocessor</a>) for that. The data processor is an extension for CiviCRM which gets data from CiviCRM and exposes this to the API (it is possible to add your own outputs, e.g, csv file, page etc..)</p>
  
  <p>At the Drupal side you need the CiviMRF Core Module (<a href="https://github.com/CiviMRF/cmrf_core" rel="nofollow noreferrer">https://github.com/CiviMRF/cmrf_core</a>). 
  The CiviMRF is capable of connecting to an external civicrm and with cmrf_views you can setup views to retrieve data from the CiviCRM API. </p>
  
  <p>With the data processor you can create your own custom API's (or views). </p>
  
  <p>All this is still work in progress but functional working. I hope to write a blog post on how the data processor works with Drupal views in the near future.</p>
  
  <p>This will also work when CiviCRM is installed in the same Drupal environment. The CMRF core module provides a 'local' connection.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-20T14:52:36.117Z
Answers.Text: I believe the question being asked here isn't "How to access a separate CMS instance with CiviCRM" but "I have a single instance with my CMS MySQL tables and CRM MySQL tables in separate databases."
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-21T09:00:44.353Z
Answers.Text: You are right and the answer is that above also works with CiviCRM installed in the same CMS.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-20T19:40:18.627Z
Answers.Text: It looks like a good way to do it but unfortunately in the Drupal 8 version of the CiviMRF Core Module there is no cmrf_views (yet).
Answers.UserDisplayName: Hans Rossel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-21T08:45:41.430Z
Answers.Text: Yes the civimrf module is not yet well suported by drupal 8. It would cost quite a bit to make it drupal 8 compatible (as drupal 8 is quite different from drupal 7). So it is almost a redevelopment of the module. My assumption earlier was that this module was easily compatible with drupal 8.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-20T10:41:45.303Z
Answers.LastActivityDate: 2018-12-21T09:02:31.340Z
Answers.LastEditDate: 2018-12-21T09:02:31.340Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.Body: <p>I had the same problem today, so I looked in the source code.</p>
  
  <p>In <code>civicrm.install</code> there's a function called <code>_civicrm_get_db_config</code>.  It's looking in the <code>$databases</code> array for an element with a key <code>civicrm</code>.  So I added this to <code>settings.php</code>:</p>
  
  <pre><code>$databases['civicrm']['default'] = array (
    'database' =&gt; 'civi_db_name',
    'username' =&gt; 'mysqluser',
    'password' =&gt; 'redacted',
    'prefix' =&gt; '',
    'host' =&gt; 'localhost',
    'port' =&gt; '3306',
    'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' =&gt; 'mysql',
  );
  </code></pre>
  
  <p>I then had to clear all caches before it worked, but work it does.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-21T00:46:17.193Z
Answers.Text: That’s awesome - thanks for posting
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-03T17:56:31.000Z
Answers.Text: This also worked when sharing the drupal database - just added this with the same credentials
Answers.UserDisplayName: Matthew Wire
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-20T20:29:29.110Z
Answers.Text: This also works to answer the question of how to install with separated dbs:
  https://civicrm.stackexchange.com/questions/26988/how-to-install-a-separated-civi-database-with-drupal-8
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-20T21:15:04.783Z
Answers.LastActivityDate: 2019-06-20T21:15:04.783Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>When setting up a Drupal 8 with separate CiviCRM database, the Drupal views cannot read the CiviCRM database: </p>
  
  <blockquote>
    <p>SQLSTATE[42S02]: Base table or view not found: 1146 Table
    'xxx.civicrm_contact' doesn't exist: SELECT civicrm_contact.id AS id,
    civicrm_contact.organization_name AS civicrm_contact_organization_name
    FROM {civicrm_contact} civicrm_contact LIMIT 11 OFFSET 0; Array ( )</p>
  </blockquote>
  
  <p>Checking the civicrm_views module I suppose there are some changes needed in the civicrm_views_views_data() function to connect to the right database for the CiviCRM data. </p>
  
  <p>I also tried to create a view based on entities from the CiviCRM Entity module, but have the same error there.</p>
  
  <p>Anybody got this working or has some hints how to do it?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-19T10:54:31.810Z
Comments.Text: Hi Hans, I know Jaap Jansma uses this extension:  https://lab.civicrm.org/extensions/dataprocessor to deal with Views from an external CiviCRM. I will point out your question to him.
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-19T14:04:53.067Z
Comments.Text: You can indeed use the data processor extension for that. You also need the CiviMRF core module from https://github.com/CiviMRF/cmrf_core (which also contains the cmrf_views module).
  The CiviMRF is capable of connecting to an external civicrm and with cmrf_views you can setup views to retrieve data from the CiviCRM API. 
  With the data processor you can create your own custom API's (or views). 
  The data processor is at the moment work in progress and not well tested but that might change in the coming months.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-19T19:05:37.743Z
Comments.Text: jaap can you add this as an Answer
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-20T01:25:46.557Z
Comments.Text: Is this specific to drupal 8? Did you try the "prefix" in settings.php the same as in drupal 7 as described here? https://docs.civicrm.org/sysadmin/en/latest/integration/drupal/views/
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-20T19:42:18.120Z
Comments.Text: @Demerit: it is indeed for Drupal 8 I'm searching, the same setup works perfectly in Drupal 7: 2 databases: 1 for Drupal and 1 for CiviCRM (to have extra security for the contact data). The prefix method is if you want both Drupal and CiviCRM in a single database.
Comments.UserDisplayName: Hans Rossel
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-20T20:30:27.557Z
Comments.Text: Actually the prefix is for separate databases - you prefix the civi tablenames with the civi database name so that drupal looks there instead of in its own database. But if you're saying that used to work in 7 but isn't working in 8, then yes it's some other problem.
Comments.UserDisplayName: Demerit
Tags: <database><drupal-views><civicrm-entity><drupal-8>
Title: How to get CiviCRM Views to work in Drupal 8 with separate CiviCRM database
ThreadText: # How to get CiviCRM Views to work in Drupal 8 with separate CiviCRM database
  
  (Asked by: username_0 on 2018-12-19)
  
  When setting up a Drupal 8 with separate CiviCRM database, the Drupal views cannot read the CiviCRM database:
  
  > SQLSTATE[42S02]: Base table or view not found: 1146 Table
  > 'xxx.civicrm\_contact' doesn't exist: SELECT civicrm\_contact.id AS id,
  > civicrm\_contact.organization\_name AS civicrm\_contact\_organization\_name
  > FROM {civicrm\_contact} civicrm\_contact LIMIT 11 OFFSET 0; Array ( )
  
  Checking the civicrm\_views module I suppose there are some changes needed in the civicrm\_views\_views\_data() function to connect to the right database for the CiviCRM data.
  
  I also tried to create a view based on entities from the CiviCRM Entity module, but have the same error there.
  
  Anybody got this working or has some hints how to do it?
  
  **Tags:** database, drupal-views, civicrm-entity, drupal-8
  
  > **Comments:**
  > **username_1**: Hi Hans, I know Jaap Jansma uses this extension:  https://lab.civicrm.org/extensions/dataprocessor to deal with Views from an external CiviCRM. I will point out your question to him.  
  > **username_2**: You can indeed use the data processor extension for that. You also need the CiviMRF core module from https://github.com/CiviMRF/cmrf_core (which also contains the cmrf_views module). The CiviMRF is capable of connecting to an external civicrm and with cmrf_views you can setup views to retrieve data from the CiviCRM API.  With the data processor you can create your own custom API's (or views).  The data processor is at the moment work in progress and not well tested but that might change in the coming months.  
  > **username_3**: jaap can you add this as an Answer  
  > **username_4**: Is this specific to drupal 8? Did you try the "prefix" in settings.php the same as in drupal 7 as described here? https://docs.civicrm.org/sysadmin/en/latest/integration/drupal/views/  
  > **username_0**: @username_4: it is indeed for Drupal 8 I'm searching, the same setup works perfectly in Drupal 7: 2 databases: 1 for Drupal and 1 for CiviCRM (to have extra security for the contact data). The prefix method is if you want both Drupal and CiviCRM in a single database.  
  > **username_4**: Actually the prefix is for separate databases - you prefix the civi tablenames with the civi database name so that drupal looks there instead of in its own database. But if you're saying that used to work in 7 but isn't working in 8, then yes it's some other problem.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_5 on 2019-06-20. Score: 9 | Accepted answer
  
  I had the same problem today, so I looked in the source code.
  In civicrm.install there's a function called _civicrm_get_db_config.  It's looking in the $databases array for an element with a key civicrm.  So I added this to settings.php:
  $databases['civicrm']['default'] = array (
    'database' => 'civi_db_name',
    'username' => 'mysqluser',
    'password' => 'redacted',
    'prefix' => '',
    'host' => 'localhost',
    'port' => '3306',
    'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' => 'mysql',
  );
  
  I then had to clear all caches before it worked, but work it does.
  
  > **Comments:**
  > **username_6**: That’s awesome - thanks for posting  
  > **username_7**: This also worked when sharing the drupal database - just added this with the same credentials  
  > **username_8**: This also works to answer the question of how to install with separated dbs: https://civicrm.stackexchange.com/questions/26988/how-to-install-a-separated-civi-database-with-drupal-8  
  
  ---
  
  ### Answer by username_2 on 2018-12-20. Score: 1
  
  You can use the data processor extension (<https://lab.civicrm.org/extensions/dataprocessor>) for that. The data processor is an extension for CiviCRM which gets data from CiviCRM and exposes this to the API (it is possible to add your own outputs, e.g, csv file, page etc..)
  
  At the Drupal side you need the CiviMRF Core Module (<https://github.com/CiviMRF/cmrf_core>).
  The CiviMRF is capable of connecting to an external civicrm and with cmrf\_views you can setup views to retrieve data from the CiviCRM API.
  
  With the data processor you can create your own custom API's (or views).
  
  All this is still work in progress but functional working. I hope to write a blog post on how the data processor works with Drupal views in the near future.
  
  This will also work when CiviCRM is installed in the same Drupal environment. The CMRF core module provides a 'local' connection.
  
  > **Comments:**
  > **username_5**: I believe the question being asked here isn't "How to access a separate CMS instance with CiviCRM" but "I have a single instance with my CMS MySQL tables and CRM MySQL tables in separate databases."  
  > **username_2**: You are right and the answer is that above also works with CiviCRM installed in the same CMS.  
  > **username_0**: It looks like a good way to do it but unfortunately in the Drupal 8 version of the CiviMRF Core Module there is no cmrf_views (yet).  
  > **username_2**: Yes the civimrf module is not yet well suported by drupal 8. It would cost quite a bit to make it drupal 8 compatible (as drupal 8 is quite different from drupal 7). So it is almost a redevelopment of the module. My assumption earlier was that this module was easily compatible with drupal 8.  
  
  ---
  
  