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 686859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:04:02+00:00 2026-05-14T02:04:02+00:00

I built myself a MySQL class which I use in all my projects. I’m

  • 0

I built myself a MySQL class which I use in all my projects. I’m about to start a project that is heavily based on user accounts and I plan on building my own class for this aswell. The thing is, a lot of the methods in the user class will be MySQL queries and methods from the MySQL class.

For example, I have a method in my user class to update someone’s password:

class user() {
    function updatePassword($usrName, $newPass)
    {
        $con = mysql_connect('db_host', 'db_user', 'db_pass');
        $sql = "UPDATE users SET password = '$newPass' WHERE username = '$userName'";
        $res = mysql_query($sql, $con);
        if($res) return true;
        mysql_close($con);
    }
}

(I kind of rushed this so excuse any syntax errors 🙂 )

As you can see that would use MySQL to update a users password, but without using my MySQL class, is this correct? I see no way in which I can use my MySQL class within my users class without it seeming dirty. Do I just use it the normal way like $DB = new DB();? That would mean including my mysql.class.php somewhere too…

I’m quite confused about this, so any help would be appreciated, thanks.

  • 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-14T02:04:03+00:00Added an answer on May 14, 2026 at 2:04 am

    Yes you have to include the mysql.class.php in order to use the class. But this is similar as in Java, Python, etc. You have to specify what you use.

    One way to make the class available in your user class would be to call the constructor with an instance of the DB class:

    class User {
        private $_db;
        public function __construct($db) {
            $this->_db = $db;
        }
    
        public function updatePassword($usrName, $newPass) {
            // use $this->_db here
        }
    
    }
    

    and then:

    require 'mysql.class.php'
    
    $user = new User(new DB());
    $user->updatePAssword('foo', 'bar');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inspired by Apple's LazyTables sample, I've just built myself a class called ImageLoader. It's
I want to build mod_wsgi against a Python which I have built myself from
I've built myself a Rails Engine that requires that the main app have a
I'm looking for a front-end that's very simple, to access a to-be-built MySQL Database.
Having built myself a decent website using ASP.NET MVC, I'm about to build an
We have a custom-built Flash-based video player that I maintain, and it needs to
I'm just learning Swing, and built a sample GUI for myself as practice. Very
As a hobby project to keep myself out of trouble, I'd like to build
Ive built a little jquery sliding div on my website that when you hover
In teaching myself php and mySQL a year or two ago, I created a

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.