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

  • Home
  • SEARCH
  • 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 3318374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:41:53+00:00 2026-05-17T22:41:53+00:00

class.mysql.php has 2 classes: MySQL and MySQLResult class.mysql.php: <?php /** * MySQL Database Connection

  • 0

class.mysql.php has 2 classes: MySQL and MySQLResult

class.mysql.php:

<?php

/**
 * MySQL Database Connection Class
 * @access public
 */
class MySQL {

    /**
     * MySQL server hostname
     * @access private
     * @var string
     */
    var $host;
    /**
     * MySQL username
     * @access private
     * @var string
     */
    var $dbUser;
    /**
     * MySQL user's password
     * @access private
     * @var string
     */
    var $dbPass;
    /**
     * Name of database to use
     * @access private
     * @var string
     */
    var $dbName;
    /**
     * MySQL Resource link identifier stored here
     * @access private
     * @var  string
     */
    var $dbConn;
    /**
     * Stores error messages for connection errors
     * @access private
     * @var string
     */
    var $connectError;

    /**
     * MySQL constructor
     * @param string host (MySQL Server hostname)
     * @param string dbUser (MySQL User Name)
     * @param string dbPass (MySQL User Password)
     * @param string dbName (Database to select)
     * @access public
     */
    function MySQL($host, $dbUser, $dbPass, $dbName) {
        $this->host = $host;
        $this->dbUser = $dbUser;
        $this->dbPass = $dbPass;
        $this->dbName = $dbName;
        $this->connectToDb();
    }

    /**
     * Establishes connection to MySQL and selects a database
     * @return void
     * @access private
     */
    function connectToDb() {
        //Make connection to MySQL server
        if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) {
            trigger_error('Could not connect to server');
            $this->connectError = true;
            //Select database
        } else if (!mysql_select_db($this->dbName, $this->dbConn)) {
            trigger_error('Could not select database');
            $this->connectError = true;
        }
    }

    /**
     * Checks for MySQL errors
     * @return boolean
     * @access public
     */
    function isError() {
        if ($this->connectError) {
            return true;
        }
        $error = mysql_error($this->dbConn);
        if (empty($error)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * Returns an instance of MySQLResult to fetch rows with
     * @param $sql string the database query to run
     * @return MySQLResult
     * @access public
     */
    function query($sql) {
        if (!$queryResource = mysql_query($sql, $this->dbConn)) {
            trigger_error('Query failed: ' . mysql_error($this->dbConn) . ' SQL: ' . $sql);
        }
        return new MySQLResult($this, $queryResource);
    }

}

/**
 * MySQLResult Data Fetching Class
 * @access public
 */
class MySQLResult {

    /**
     * Instance of MySQL providing database connection
     * @access private
     * @var MySQL
     */
    var $mysql;
    /**
     * Query resource
     * @access private
     * @var resource
     */
    var $query;

    /**
     * MySQLResult constructor
     * @param object mysql (instance of MySQL class)
     * @param resource query (MySQL query resource)
     * @access public
     */
    function MySQLResult(&$mysql, $query) {
        $this->mysql = &$mysql;
        $this->query = $query;
    }

    /**
     * Fetches a row from the result
     * @return array
     * @access public
     */
    function fetch() {
        if ($row = mysql_fetch_array($this->query, MYSQL_ASSOC)) {
            return $row;
        } else if ($this->size() > 0) {
            mysql_data_seek($this->query, 0);
            return false;
        } else {
            return false;
        }
    }

    /**
     * Checks for MySQL Errors
     * @return boolean
     * @access public
     */
    function isError() {
        return $this->mysql->isError();
    }

    /**
     * Returns the number of rows selected
     * @return int
     * @access public
     */
    function size() {
        return mysql_num_rows($this->query);
    }

    /**
     * Returns the ID of the last row inserted
     * @return int
     * @access public
     */
    function insertID() {
        return mysql_insert_id($this->mysql->dbConn);
    }

}

login.php is checking for username and password after being submitted from a form. If fields are not empty check database for an entry. If there is an entry then set the session.

login.php:

<?php
//MySQL class
require_once('database/class.mysql.php');

//Session class
require_once('session/class.session.php');

//Instantiate the mysql class
require_once('database/dbconnect.php');
$db = new MySQL($host, $dbUser, $dbPass, $dbName);

//Instantiate the Session class
$session = new Session();

//$session->destroy();
if (!$session->get('username')) {
    if (isset($_POST['submit'])) {
        $username = $_POST['username'];
        $password = $_POST['password'];

        if (!empty($username) && !empty($password)) {
            $sql = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
            $db->query($sql);
            if ($db->size() == 1) {
                $session->set('username', $username);
            }
        }
    }
}

if (!$session->get('username')) {
    echo 'not set';
}
?>
<html>
    <head>
    </head>
    <body>


        <form method="post" action="">
            Username: <input type="text" name="username" /><br />
            Password: <input type="text" name="password" /><br />
            <input type="submit" name="submit" value="Submit" />
        </form>

    </body>
</html>

So here’s the question, im am using this code in login.php to check for database entry:

if ($db->size() == 1)

This code is obviously wrong because $db is an object of MySQL class but the size() method is in the MySQLResult class. Is there a simply way to get to size()? Thanks in advance

This is my error:

Fatal error: Call to undefined method MySQL::size()
  • 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-05-17T22:41:54+00:00Added an answer on May 17, 2026 at 10:41 pm

    $db->query($sql); returns a MySQLResult. You have to do something like

    $result = $db->query($sql);
    if ($result->size() == 1) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.