# PHP Classes

**URL:** <https://forum.kirupa.com/t/php-classes/72316>\
**Category:** programming\
**Created:** [December 4, 2004, 11:45am UTC](https://forum.kirupa.com/t/php-classes/72316 "2004-12-04T11:45:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [December 4, 2004, 11:45am UTC](https://forum.kirupa.com/t/php-classes/72316/1 "2004-12-04T11:45:51Z")

</div>

Yesterday i found the wonderfull world of php classes, i do understand how they work and how they look like, but i never tried to really program in it…

after programming a complete database class, including query’s and stuff.  
i wanted to do a class for a news system… problem is, you need to connect and send query’s then… here is where i found my first problem.

```php

class Database{
	function Database($settings){
		// some code
	}
	function connect(){
		// some code
	}
	function close(){
		// some code
	}
	function query($query){
		// some code, returning the result in array
	}
}
$Database = new Database($settings);

class News{
	function show($limit){
		$Database->connect();
		$Array = $Database->query("some query");
		return $Array;
	}
}
$News = new News;
$News->show(5);

```

i know this dozn’t work, but you all get the idea, what is correct code for this?
