title: Using Raw SQL in SuiteCRM
body: <p>So, this is my first encounter with SuiteCRM or any other CRM for that matter. I need to query the db on a table that is not used by the CRM for our quote system. So, I have created the module using module builder and modified the module file so that it uses the correct table. The problem is that when the query runs, SuiteCRM still adds its default where clauses and adds the deleted = 0 condition to the query.
  So, I tried using the method that is described on <a href="https://stackoverflow.com/questions/12192010/how-can-i-retrieve-all-the-records-from-a-table-in-sugarcrm">this SO page</a>. That doesn't work as I get the an error that I am using an undefined variable (db) and that I am calling to a member function fetchByAssoc() on a non-object. Now, I am placing the code in the moduleName.php file. Maybe that is my issue. I don't know as I have never worked on any other CRM project. If anyone can point me in the right direction as to what I will need to do to be able to query a different table other than the default CRM table and then show the results from that query inside of a dashlet, your help will be greatly appreciated.
  I got the errors fixed. They were my fault as I had not referenced the object.
  So, as requested, here is some of my code. This is my php file.</p>
  
  <pre><code>    &lt;?php
  
      if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  
      require_once('include/Dashlets/Dashlet.php');
  
      class FrtwQuotesDashlet extends Dashlet {
      var $height = '200'; // height of the dashlet
      var $quoteData = "";
  
      /**
       * Constructor
       *
       * @global string current language
       * @param guid $id id for the current dashlet (assigned from Home module)
       * @param array $def options saved for this dashlet
       */
      function FrtwQuotesDashlet($id, $def) {
          $this-&gt;loadLanguage('FrtwQuotesDashlet');
  
          if(!empty($def['height'])) // set a default height if none is set
              $this-&gt;height = $def['height'];
  
          parent::Dashlet($id); // call parent constructor
  
          $this-&gt;isConfigurable = true; // dashlet is configurable
          $this-&gt;hasScript = false;  // dashlet has javascript attached to it
  
          // if no custom title, use default
          if(empty($def['title'])) $this-&gt;title =   $this-&gt;dashletStrings['LBL_TITLE'];
          else $this-&gt;title = $def['title'];
      }
  
      /**
       * Displays the dashlet
       *
       * @return string html to display dashlet
       */
      function display() {
           $sql = "SELECT QuoteNbr, crmname, ShipToCity FROM quotes.quotehdr LIMIT 10";
         $result = $GLOBALS["db"]-&gt;query($sql);
         $quoteData = "&lt;table&gt;";
             while($quotes = $GLOBALS["db"]-&gt;fetchByAssoc($result)){
                 foreach ($quotes as $quote) {
                     $quoteData .="&lt;tr&gt;&lt;td&gt;".$quote[0]."&lt;/td&gt;&lt;td&gt;".$quote[1]."&lt;/td&gt;&lt;td&gt;".$quote[2]."&lt;/td&gt;&lt;/tr&gt;";
                 }
  
             }
  
           $ss = new Sugar_Smarty();
          //assign variables
          //$ss-&gt;assign('greeting', $this-&gt;dashletStrings['LBL_GREETING']);
          $ss-&gt;assign('quoteData', $this-&gt;quoteData);
          $ss-&gt;assign('height', $this-&gt;height);
  
          $str = $ss-&gt;fetch('custom/modules/Home/FrtwQuotesDashlet/FrtwQuotesDashlet.tpl');
          return parent::display().$str; 
      }
  }
  ?&gt;
  </code></pre>