Jump to content

Try to understand how to build php classes


Guest Katun

Recommended Posts

Guest Katun

Hi, I'm a truly beginner into OOP things and because of that I'm very confused how to do it right.

I've builded a class for mysql database connection and now I intend to build another one for login.

The login class must use database connection object of course.

 

My questions are:

1. It is right to create the login class like an extended class of mysql connect?

2. It's usual to do it in that way?

3. Can somebody teach me about good practices in this?

 

Because I don't want to start into wrong direction.

:unsure:

Link to comment
Share on other sites

Sorry for the delayed response, I must have missed this one originally...

 

To answer answer your question:

 

I personally would keep the login class and the mysql class separate. The login class may use the database, but it isn't a database object itself. I think it would make more sense to keep them separate and simply have the login class be able to access the database object.

 

I personally would avoid extending your classes unless it makes clear sense and the classes are clearly related. For example, perhaps you would have a general database class, and then extend it with a new class for a specific type of database that needs specific functionality.

 

I'm not sure exactly what you are asking in regards to "can somebody teach me about good practices in this"? What specifically? OOP in general? A lot of this stuff you will pick up as you gain more experience, and I don't really think that it is something that can be summarized in a couple paragraphs. This has some resources that might help you get started though: http://stackoverflow.com/questions/293152/best-way-to-learn-net-oop-best-practices

 

Also, I have written some intermediate level tutorials on building a OOP based login system, and also a series on building a simple content management system that uses code from the OOP login system series. These videos and source files are available to premium subscribers in the KS Video Library (in the PHP Section: http://killersites.com/university/) and the CMS course is also available as a standalone course: http://killervideostore.com/video-courses/build-a-cms.php

 

Those videos may help give you a start on your own login system, and I'm always around on the forum to answer questions.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...