title: Fatal error: Undefined class constant
body: <p>So I'm trying to use <a href="http://www.phpclasses.org/package/7800-PHP-MySQL-database-access-wrapper-using-MySQLi.html" rel="noreferrer">this</a> mysqli connection class (code below) but I am receiving the error message: <strong>Fatal error: Undefined class constant 'DBUSER' [...]</strong> I can't figure out why because I have set all the database connection credentials and included the config file.</p>
  
  <p>My db.config.class.php:</p>
  
  <pre><code>class config {
  
      public static $DBSERVER = "localhost"; // Set the IP or hostname of the database server you wish to connect to
      public static $DBNAME = "**REMOVED**"; // Set the name of the database you wish to connect to
      public static $DBUSER = "**REMOVED**"; // set the database user name you wish to use to connect to the database server
      public static $DBPASSWORD = "**REMOVED**"; // set the password for the username above
      public static $DBPORT = 3306;
      public static $TABLEPREFIX = "";
  
  }
  </code></pre>
  
  <p>mysqli.class.php:</p>
  
  <pre><code>include('db.config.class.php');
  
  /**
   * My-SQL database class
   *
   * @name        mysql
   * @version     2
   * @author      Leigh Edwards
   * @category    PHP
   */
  
  class Dbconnect {
  
      // leave blank if used for multiple users and call setUser method
      private $sqlUser = "";
  
      // leave blank if used for multiple users and call setPassword method
      private $sqlPassword = "";
  
      // set this to the database name you wish to use. If this class is used to access a number of Databases
      // leave blank and call the select method to select the desired database
      private $sqlDatabase = "";
  
      // set this to the database server address. If you are using this class to connect to differant server
      // leave blank and call the setHost method
      private $sqlHost = "";
  
      // Set this to the prefix of your tables if you set one while installing.
      // default = ""
      public $table_prefix = "";
      private $result; // Query result
      private $querycount; // Total queries executed
      private $linkid;
  
      /////////////////////////////////////////END CONFIG OPTIONS/////////////////////////////////////////////////////
  
  
      function __construct() {
  
          $this-&gt;loadDefaults ();
  
          $this-&gt;connect ( $this-&gt;sqlHost, $this-&gt;sqlUser, $this-&gt;sqlPassword, $this-&gt;sqlDatabase );
  
          $this-&gt;select ( $this-&gt;sqlDatabase );
  
  
      }
  
      /*
       * method to load the object with the defaut settings
       */
  
      private function loadDefaults() {
          $this-&gt;sqlUser = config::DBUSER;
          $this-&gt;sqlPassword = config::DBPASSWORD;
          $this-&gt;sqlHost = config::DBSERVER;
          $this-&gt;sqlDatabase = config::DBNAME;
          $this-&gt;table_prefix = config::TABLEPREFIX;
      }
  
      public function getResult() {
  
          return $this-&gt;result;
  
      }
  
      /**
       * method to return the prefix for the sql tables
       *
       * @return = string $this-&gt;table_prefix
       */
  
      public function get_tablePrefix() {
  
          return $this-&gt;table_prefix;
  
      }
  
      /**
       * function to return a string from within another string
       * found between $beginning and $ending
       *
       * @param string $source
       * @param string $beginning
       * @param string $ending
       * @param string $init_pos
       */
  
      function get_middle($source, $beginning, $ending, $init_pos) {
  
          $beginning_pos = strpos ( $source, $beginning, $init_pos );
  
          $middle_pos = $beginning_pos + strlen ( $beginning );
  
          $ending_pos = strpos ( $source, $ending, $beginning_pos + 1 );
  
          $middle = substr ( $source, $middle_pos, $ending_pos - $middle_pos );
  
          return $middle;
  
      }
  
      /**
       * method to connect to the MySQL database server.
       *
       * @param   string  $sqlHost
       * @param   string  $sqlUser
       * @param   string  $sqlPassword
       **/
  
      function connect($sqlHost, $sqlUser, $sqlPassword, $sqlDatabase) {
          try {
              $this-&gt;linkid = mysqli_connect ( $sqlHost, $sqlUser, $sqlPassword, $sqlDatabase, 3306 );
              if (! $this-&gt;linkid) {
                  die ( 'Connect Error (' . mysqli_connect_errno () . ') ' . mysqli_connect_error () );
              }
          } catch ( Exception $e ) {
              die ( $e-&gt;getMessage () );
          }
      }
  
      /**
       * method to select the database to use
       * @param string $sqlDatabase
       */
  
      function select($sqlDatabase) {
          try {
              if (! @mysqli_select_db ( $sqlDatabase, $this-&gt;linkid )) {
                  throw new Exception ( "The Selected Database Can Not Be Found On the Database Server. $sqlDatabase (E2)" );
              }
          } catch ( Exception $e ) {
              die ( $e-&gt;getMessage () );
          }
      }
  
      /**
  
       * method to query sql database
       * take mysql query string
       * returns false if no results or NULL result is returned by query
       * if query action is not expected to return results eg delete
       * returns false on sucess else returns result set
       *
       * NOTE: If you requier the the actual result set call one of the fetch methods
       *
       * @param string $query
       * @return boolian true or false
       */
  
      function query($query) {
          // ensure clean results
          unset ( $this-&gt;result );
          // make query
          $this-&gt;result = mysqli_query ( $query, $this-&gt;linkid );
          if (! $this-&gt;result) {
              echo "&lt;br&gt;Query faild: $query";
              return FALSE;
          } else {
              return true;
          }
      }
  
      /**
       * method to return the number of rows affected by the
       * last query exicuted
       * @return int
       */
  
      function affectedRows() {
  
          $count = mysqli_affected_rows ( $this-&gt;linkid );
          return $count;
  
      }
  
      /**
       * method to return the number of rows in the result set
       * returned by the last query
       */
  
      function numRows() {
  
          $count = @mysqli_num_rows ( $this-&gt;result );
  
          return $count;
  
      }
  
      /**
       * method to return the result row as an object
       * @return  object
       */
  
      function fetchObject() {
  
          $row = @mysqli_fetch_object ( $this-&gt;result );
  
          return $row;
  
      }
  
      /**
       * method to return the result row as an indexed array
       * @return array
       */
  
      function fetchRow() {
  
          $row = @mysqli_fetch_row ( $this-&gt;result );
  
          return $row;
  
      }
  
      /**
       * method to return the result row as an associative array.
       * @return array
       **/
  
      function fetchArray() {
  
          $row = @mysqli_fetch_array ( $this-&gt;result, mysqli_ASSOC );
  
          return $row;
  
      }
  
      /**
       * method to return total number queries executed during
       * the lifetime of this object.
       *
       * @return int
       */
  
      function numQueries() {
  
          return $this-&gt;querycount;
  
      }
  
      function setResult($resultSet) {
  
          $this-&gt;result = $resultSet;
  
      }
  
      /**
       * method to return the number of fields in a result set
       * @return int
       **/
  
      function numberFields() {
  
          return @mysqli_num_fields ( $this-&gt;result );
  
      }
  
      /**
       * method to return a field name given an integer offset
       * @return  string
       **/
  
      function fieldName($offset) {
  
          return @mysqli_field_name ( $this-&gt;result, $offset );
  
      }
  
      /**
       * method to return the results of the last query
       * in html table
       *
       * This method uses the $actions string to pass html code
       * this is added to the table to enable display of images or links
       * in the last columb of the table
       *
       * if boolian false is passed no html is add to the result table
       * $startCol sets the col to start displaying 0 being the first
       *
       * @param int $startCol
       * @param string or boolian false $actions
       * @return string containing html code to dispay the table
       */
  
      function getResultAsTable($startCol, $actions = "") {
  
          if ($this-&gt;numrows () &gt; 0) {
  
              // Start the table
              $resultHTML = "&lt;table width=\"80%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\"&gt;&lt;tr&gt;";
  
              $resultHTML .= "&lt;td&gt;&lt;table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"&gt;&lt;tr&gt;";
  
              $x = $startCol;
  
              // Output the table header
              $fieldCount = $this-&gt;numberFields ();
  
              for($i = $x; $i &lt; $fieldCount; $i ++) {
  
                  $rowName = $this-&gt;fieldName ( $i );
  
                  $resultHTML .= "&lt;th align=\"left\"&gt;$rowName&lt;/th&gt;";
  
              }
  
              if (! $actions === false) {
  
                  $resultHTML .= "&lt;th align=\"left\"&gt;actions&lt;/th&gt;";
  
              }
  
              $resultHTML .= "&lt;/tr&gt;";
  
              while ( $row = $this-&gt;fetchRow () ) {
  
                  $resultHTML .= "&lt;tr&gt;";
  
                  for($i = $x; $i &lt; $fieldCount; $i ++)
  
                      $resultHTML .= "&lt;td align=\"left\"&gt;" . htmlentities ( $row [$i] ) . "&lt;/td&gt;";
  
                  if (! $actions === false) {
  
                      // Replace VALUE with the correct primary key
                      $action = str_replace ( "VALUE", $row [0], $actions );
  
                      $resultHTML .= "&lt;td nowrap align=\"left\"&gt;$action&lt;/td&gt;";
  
                  }
  
                  $resultHTML .= "&lt;/tr&gt;";
  
              }
  
              $resultHTML .= "&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
  
          } else {
  
              $resultHTML = "";
  
          }
  
          return $resultHTML;
  
      }
  
      /**
       * method to retun the value of a given colum using one where clause
       * @param $table
       * @param $col
       * @param $val1
       * @param $col2
       */
  
      function getRow($table, $col, $val1, $col2) {
  
          $query = "SELECT '$col2' FROM " . $this-&gt;table_prefix . $table . " WHERE $col = '$val1'";
  
          $this-&gt;query ( $query );
  
          $resultArray = $this-&gt;fetchArray ();
  
          return $resultArray [$col2];
  
      }
  
      /**
       * method to test if a row conatining $x in the feild $y exists in the given $table
       * method returns true or false
       * @param $table
       * @param $col
       * @param $val
       * @return boolian
       */
  
      function rowExistsInDB($table, $col, $val) {
          $this-&gt;query ( "SELECT $col FROM '" . $this-&gt;table_prefix . $table . "' WHERE '$col' = '$val'" );
          if ($this-&gt;numRows () &gt; 0) {
              return true;
          } else {
              return false;
          }
      }
  
      function rowExistsInDB2($table, $col, $val, $col2, $val2) {
  
          $query = "SELECT " . $col . " FROM " . $this-&gt;table_prefix . $table . " WHERE " . $col . " = '" . mysqli_real_escape_string ( $val ) . "' AND " . $col2 . " = '" . mysqli_real_escape_string ( $val2 ) . "'";
          $this-&gt;query ( $query );
          if ($this-&gt;numRows () &gt; 0) {
              return true;
          } else {
              return false;
          }
      }
  
      /**
       * method to delete all rows where $col=$val in $table
       * returns int of number of affected rows or false on fail
       *
       * @param string $table
       * @param string $col
       * @param string $val
       * @return int
       */
      function deleteRow($table, $col, $val) {
          $this-&gt;query ( "DELETE FROM '" . $this-&gt;table_prefix . $table . "' WHERE '$col' = '$val'" );
          return $this-&gt;result;
      }
  
      // Misc methods to do some convertions and stuff
  
  
      // round or pad to 2 decimal points
      function formatNum($num, $dec = 2) {
          for($x = 0; $x &lt;= 5; $x ++) {
              $num = sprintf ( "%01." . ($dec + $x) . "f", $num );
              return $num;
          }
      }
      /**
       * method to reverse the order of a given date
       * and fix to mysql date format
       * so DD/MM/YYYY becomes YYYY-MM-DD
       *
       * @param string $date
       * @return string
       */
  
      function revDate($date) {
  
          // first split the date string @ / int o three parts
          $dateArray = explode ( '/', $date, 3 );
  
          // then reorder them to YYY-MM-DD
          $revDate = array_reverse ( $dateArray );
  
          $i = 0;
  
          foreach ( $revDate as $eliment ) {
  
              $correctDate .= $eliment;
  
              if ($i &lt; 2) {
  
                  $correctDate .= "-";
  
              }
  
              $i ++;
  
          }
  
          return $correctDate;
  
      }
  
      /**
       * method to revers dates taken from sql database
       * so YYYY-MM-DD becomes DD/MM/YYYY
       *
       * @param string $date
       * @return string
       */
  
      function revSqlDate($date) {
  
          // first split the date string @ / int o three parts
          $dateArray = explode ( '-', $date, 3 );
  
          // then reorder them to DD/MM/YYYY
          $revDate = array_reverse ( $dateArray );
  
          $i = 0;
  
          foreach ( $revDate as $eliment ) {
  
              $correctDate .= $eliment;
  
              if ($i &lt; 2) {
  
                  $correctDate .= "/";
  
              }
  
              $i ++;
  
          }
  
          return $correctDate;
  
      }
  
  }
  </code></pre>