Answers.Body: <p>What you're looking for is <code>civix generate:entity</code>.  It's marked as "EXPERIMENTAL AND INCOMPLETE" on my copy of civix - though my version might be old.  Either way, it should point you in the right direction.</p>
  
  <p>UPDATE: While you should still run <code>civix generate:entity</code>, at the time of this writing, it will create a BAO but NOT a DAO file for you.  Use Xavier's technique (the accepted answer).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-25T20:48:41.337Z
Answers.LastActivityDate: 2016-04-23T21:33:27.883Z
Answers.LastEditDate: 2016-04-23T21:33:27.883Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>Alternatively, I tend to create the file in sql and then create a DAO in my extension with the few functions that are required. Check <a href="https://github.com/CiviCooP/no.maf.oppgavexml/blob/master/CRM/Oppgavexml/DAO/Oppgave.php" rel="nofollow">https://github.com/CiviCooP/no.maf.oppgavexml/blob/master/CRM/Oppgavexml/DAO/Oppgave.php</a> for an example of a DAO I have copied and pasted into my extension for a table I created in the Upgrade class using</p>
  
  <pre><code>$this-&gt;executeSqlFile('sql/create_civicrm_oppgave.sql');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-26T10:43:26.393Z
Answers.LastActivityDate: 2015-06-26T10:43:26.393Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>What I did for the sepa extension is a bit of a hack, but worked ok:</p>
  
  <p>write the xml schema files, as you have them on the (development version) core and run xml/phpGencode.php to generate the dao, that you then copy into the extension folders and voila, you got the tables ready to use (for a few more lines, you got the api files, worthwhile IMO)</p>
  
  <p>The process is now detailed in our <a href="https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity" rel="nofollow noreferrer">developer book</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-07T02:51:28.423Z
Answers.Text: This means BAO is still need to be written manually. I found a standard guideline, which needs to be followed, but I am assuming this needs to be done manually.
Answers.UserDisplayName: Siddharth Gupta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-26T04:14:55.220Z
Answers.Text: Detailed steps for this process are now documented here: https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-01T15:56:27.690Z
Answers.Text: What is development version; I have installed civicrm in my pc with Drupal but could not see the XML folder in civicrm root directory
Answers.UserDisplayName: ManiMuthuPandi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-01T16:20:56.527Z
Answers.Text: @Xavier: how to get the development version; In my pc I installed civicrm with drupla 7; No XML folder or xml/phpGencode.php
Answers.UserDisplayName: ManiMuthuPandi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-03T07:17:09.833Z
Answers.Text: @ManiMuthuPandi, start a new question ;)
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-25T20:48:38.467Z
Answers.LastActivityDate: 2017-04-27T15:20:52.270Z
Answers.LastEditDate: 2017-04-27T15:20:52.270Z
Answers.UserDisplayName: Xavier
Body: <p>I have added tables to my database by writing SQL commands in a sql folder as specified in the given link. 
  <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension#CreateaModuleExtension-Addadatabaseupgrader/Installer/uninstaller">Add a database upgrader / Installer / uninstaller</a>.</p>
  
  <p>What I am exactly looking for is a method to access these tables, do I need to write direct SQL for adding records to the table or I should create corresponding DAO and BAO to access the table.</p>
  
  <p>How to create DAO and BAO for a given table in an extension?</p>
  
Tags: <custom-fields><database><gsoc>
Title: How do I add a new table to my extension?
ThreadText: # How do I add a new table to my extension?
  
  (Asked by: username_0 on 2015-06-25)
  
  I have added tables to my database by writing SQL commands in a sql folder as specified in the given link.
  [Add a database upgrader / Installer / uninstaller](http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension#CreateaModuleExtension-Addadatabaseupgrader/Installer/uninstaller).
  
  What I am exactly looking for is a method to access these tables, do I need to write direct SQL for adding records to the table or I should create corresponding DAO and BAO to access the table.
  
  How to create DAO and BAO for a given table in an extension?
  
  **Tags:** custom-fields, database, gsoc
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2015-06-25. Score: 5 | Accepted answer
  
  What I did for the sepa extension is a bit of a hack, but worked ok:
  
  write the xml schema files, as you have them on the (development version) core and run xml/phpGencode.php to generate the dao, that you then copy into the extension folders and voila, you got the tables ready to use (for a few more lines, you got the api files, worthwhile IMO)
  
  The process is now detailed in our [developer book](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity)
  
  > **Comments:**
  > **username_0**: This means BAO is still need to be written manually. I found a standard guideline, which needs to be followed, but I am assuming this needs to be done manually.  
  > **username_4**: Detailed steps for this process are now documented here: https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity  
  > **username_5**: What is development version; I have installed civicrm in my pc with Drupal but could not see the XML folder in civicrm root directory  
  > **username_5**: @username_3: how to get the development version; In my pc I installed civicrm with drupla 7; No XML folder or xml/phpGencode.php  
  > **username_3**: @username_5, start a new question ;)  
  
  ---
  
  ### Answer by username_1 on 2015-06-25. Score: 2
  
  What you're looking for is `civix generate:entity`. It's marked as "EXPERIMENTAL AND INCOMPLETE" on my copy of civix - though my version might be old. Either way, it should point you in the right direction.
  
  UPDATE: While you should still run `civix generate:entity`, at the time of this writing, it will create a BAO but NOT a DAO file for you. Use username_3's technique (the accepted answer).
  
  
  ---
  
  ### Answer by username_2 on 2015-06-26. Score: 1
  
  Alternatively, I tend to create the file in sql and then create a DAO in my extension with the few functions that are required. Check <https://github.com/username_2/no.maf.oppgavexml/blob/master/CRM/Oppgavexml/DAO/Oppgave.php> for an example of a DAO I have copied and pasted into my extension for a table I created in the Upgrade class using
  
  ```
  $this->executeSqlFile('sql/create_civicrm_oppgave.sql');
  
  ```
  
  
  ---
  
  