OOP PHP Class Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

OOP PHP Class Question

Post by anthony88guy »

After another leave home PHP... I'm back. haha

Well I decided that I will writing OOP PHP(4) after reviewing some of my old code...

But I had a question before I do so. I'd like to create a login class along with a mysql class that will work together. How would I write a class that's dependent on another class? I read something about extending a class to another class, is this what I want?

Code: Select all

<?php
class Login extends Mysql
{
	function checkUsername($username)
	{
		$data = $mysql->query("SELECT * FROM `blahhh` WHERE username = '" . $username . "' LIMIT 1") or $mysql->raise_error();
		
		if( $mysql->num_rows($data) != 1 )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}
?>
How would I integrate the other class?

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The class code you've provided would make Login a descendant of the Mysql class. Is Login a Mysql? I don't think so. Instead it would use a Mysql class.

Take a look at threads mentioning the term "compositing," "composite" or derivatives thereof.
Post Reply