title: How to create a table in Moodle database automatically when installing a new plug-in in Moodle?
body: <p>I create a new plug-in in report of courses in Moodle.
  In my program, I need save some data in a new table in Moodle database.
  Before it, I was creating that table manually and add data in code like this:</p>
  
  <pre><code>      global $DB;
        $record = new stdClass;
  
        $record-&gt;firstvalue=$firstvalue;
        $record-&gt;secondvalue=$secondvalue; 
        $record-&gt;courseid=$id;        
        $record-&gt;name= $fromform-&gt;name;
        $record-&gt;ytitle=$ytitle;
        $record-&gt;xtitle=$xtitle;
        $record-&gt;value=$values;
  
        $DB-&gt;insert_record('chart', $record);
  </code></pre>
  
  <p>But now, I need create that table automatically, when this plug-in install in another computer.
  How can I do that?</p>