Answers.Body: <p>The short answer is no. I assume your table doesn't represent an entity or you would have just created it as an entity and then it would be available to the api.</p>
  <p>You can always use CRM_Core_DAO::executeQuery() - it's not technically api but it's used everywhere.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-14T15:39:48.707Z
Answers.LastActivityDate: 2024-07-14T15:39:48.707Z
Answers.UserDisplayName: Demerit
Body: <p>If I create a new custom table directly in the database (mysql/wordpress), is there a way to access that table using the civicrm api (read and/or write)?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-07-15T12:48:32.497Z
Comments.Text: Ideally you should add an entity and not a custom table with SQL (see https://docs.civicrm.org/dev/en/latest/step-by-step/create-entity/ or https://github.com/systopia/de.systopia.eck
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-07-15T14:58:21.247Z
Comments.Text: Alternatively, if interacting with WordPress and CiviCRM thru a wordpress plugin, you can use wordpress $wpdb to access any tables in the db.
Comments.UserDisplayName: jsherk
Tags: <wordpress><api><api4>
Title: using API4 to access a custom table in the database
ThreadText: # using API4 to access a custom table in the database
  
  (Asked by: username_0 on 2024-07-14)
  
  If I create a new custom table directly in the database (mysql/wordpress), is there a way to access that table using the civicrm api (read and/or write)?
  
  **Tags:** wordpress, api, api4
  
  > **Comments:**
  > **username_1**: Ideally you should add an entity and not a custom table with SQL (see https://docs.civicrm.org/dev/en/latest/step-by-step/create-entity/ or https://github.com/systopia/de.systopia.eck  
  > **username_0**: Alternatively, if interacting with WordPress and CiviCRM thru a wordpress plugin, you can use wordpress $wpdb to access any tables in the db.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-07-14. Score: 0 | Accepted answer
  
  The short answer is no. I assume your table doesn't represent an entity or you would have just created it as an entity and then it would be available to the api.
  
  You can always use CRM\_Core\_DAO::executeQuery() - it's not technically api but it's used everywhere.
  
  
  ---
  
  