Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9277679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:10:06+00:00 2026-06-18T17:10:06+00:00

So I’m trying to use this mysqli connection class (code below) but I am

  • 0

So I’m trying to use this mysqli connection class (code below) but I am receiving the error message: Fatal error: Undefined class constant ‘DBUSER’ […] I can’t figure out why because I have set all the database connection credentials and included the config file.

My db.config.class.php:

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 = "";

}

mysqli.class.php:

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->loadDefaults ();

        $this->connect ( $this->sqlHost, $this->sqlUser, $this->sqlPassword, $this->sqlDatabase );

        $this->select ( $this->sqlDatabase );


    }

    /*
     * method to load the object with the defaut settings
     */

    private function loadDefaults() {
        $this->sqlUser = config::DBUSER;
        $this->sqlPassword = config::DBPASSWORD;
        $this->sqlHost = config::DBSERVER;
        $this->sqlDatabase = config::DBNAME;
        $this->table_prefix = config::TABLEPREFIX;
    }

    public function getResult() {

        return $this->result;

    }

    /**
     * method to return the prefix for the sql tables
     *
     * @return = string $this->table_prefix
     */

    public function get_tablePrefix() {

        return $this->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->linkid = mysqli_connect ( $sqlHost, $sqlUser, $sqlPassword, $sqlDatabase, 3306 );
            if (! $this->linkid) {
                die ( 'Connect Error (' . mysqli_connect_errno () . ') ' . mysqli_connect_error () );
            }
        } catch ( Exception $e ) {
            die ( $e->getMessage () );
        }
    }

    /**
     * method to select the database to use
     * @param string $sqlDatabase
     */

    function select($sqlDatabase) {
        try {
            if (! @mysqli_select_db ( $sqlDatabase, $this->linkid )) {
                throw new Exception ( "The Selected Database Can Not Be Found On the Database Server. $sqlDatabase (E2)" );
            }
        } catch ( Exception $e ) {
            die ( $e->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->result );
        // make query
        $this->result = mysqli_query ( $query, $this->linkid );
        if (! $this->result) {
            echo "<br>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->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->result );

        return $count;

    }

    /**
     * method to return the result row as an object
     * @return  object
     */

    function fetchObject() {

        $row = @mysqli_fetch_object ( $this->result );

        return $row;

    }

    /**
     * method to return the result row as an indexed array
     * @return array
     */

    function fetchRow() {

        $row = @mysqli_fetch_row ( $this->result );

        return $row;

    }

    /**
     * method to return the result row as an associative array.
     * @return array
     **/

    function fetchArray() {

        $row = @mysqli_fetch_array ( $this->result, mysqli_ASSOC );

        return $row;

    }

    /**
     * method to return total number queries executed during
     * the lifetime of this object.
     *
     * @return int
     */

    function numQueries() {

        return $this->querycount;

    }

    function setResult($resultSet) {

        $this->result = $resultSet;

    }

    /**
     * method to return the number of fields in a result set
     * @return int
     **/

    function numberFields() {

        return @mysqli_num_fields ( $this->result );

    }

    /**
     * method to return a field name given an integer offset
     * @return  string
     **/

    function fieldName($offset) {

        return @mysqli_field_name ( $this->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->numrows () > 0) {

            // Start the table
            $resultHTML = "<table width=\"80%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\"><tr>";

            $resultHTML .= "<td><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><tr>";

            $x = $startCol;

            // Output the table header
            $fieldCount = $this->numberFields ();

            for($i = $x; $i < $fieldCount; $i ++) {

                $rowName = $this->fieldName ( $i );

                $resultHTML .= "<th align=\"left\">$rowName</th>";

            }

            if (! $actions === false) {

                $resultHTML .= "<th align=\"left\">actions</th>";

            }

            $resultHTML .= "</tr>";

            while ( $row = $this->fetchRow () ) {

                $resultHTML .= "<tr>";

                for($i = $x; $i < $fieldCount; $i ++)

                    $resultHTML .= "<td align=\"left\">" . htmlentities ( $row [$i] ) . "</td>";

                if (! $actions === false) {

                    // Replace VALUE with the correct primary key
                    $action = str_replace ( "VALUE", $row [0], $actions );

                    $resultHTML .= "<td nowrap align=\"left\">$action</td>";

                }

                $resultHTML .= "</tr>";

            }

            $resultHTML .= "</table></td></tr></table>";

        } 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->table_prefix . $table . " WHERE $col = '$val1'";

        $this->query ( $query );

        $resultArray = $this->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->query ( "SELECT $col FROM '" . $this->table_prefix . $table . "' WHERE '$col' = '$val'" );
        if ($this->numRows () > 0) {
            return true;
        } else {
            return false;
        }
    }

    function rowExistsInDB2($table, $col, $val, $col2, $val2) {

        $query = "SELECT " . $col . " FROM " . $this->table_prefix . $table . " WHERE " . $col . " = '" . mysqli_real_escape_string ( $val ) . "' AND " . $col2 . " = '" . mysqli_real_escape_string ( $val2 ) . "'";
        $this->query ( $query );
        if ($this->numRows () > 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->query ( "DELETE FROM '" . $this->table_prefix . $table . "' WHERE '$col' = '$val'" );
        return $this->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 <= 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 < 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 < 2) {

                $correctDate .= "/";

            }

            $i ++;

        }

        return $correctDate;

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:10:07+00:00Added an answer on June 18, 2026 at 5:10 pm

    Write as:

    config::$DBUSER;
    

    and etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.