Jump to content

[PHP5] Class problems


Drezard

Recommended Posts

Im getting this error:

 

 

Parse error: syntax error, unexpected T_NEW in C:\xampp\htdocs\input.class.php on line 17

 

 

Heres the code for input.class.php:

 

<?php

require_once('database.class.php');

class input {

	private $database = new database;

	function input () {

		$this->database->moderator();

	}

}

?>

 

heres the code for database.class.php:

 

<?php

class database {

	// declare a few public variables
	private $database_host;
	private $database_username;
	private $database_password;
	private $database_database;
	private $database_connection;

	// connect to the database
	function connect() {

		$this->database_connection = mysql_connect($this->database_host, $this->database_username, $this->database_password);

		mysql_select_db($this->database_database, $this->database_connection);

	}

	// set up the database server constants
	function database () {

		$this->database_host = 'localhost';
		$this->database_database = 'alias';

	}

	// set up a moderator user, priveleges: SELECT, INSERT, UPDATE, DELETE
	// this user is used in the end-user app for anything more then just SELECT privelege job
	function moderator () {

		$this->database_username = 'moderator';
		$this->database_password = '******';

		$this->connect();

	}

	// set up a basic user, priveleges: SELECT
	// this user is used in the end-user app to do any SELECT jobs no more priveleges
	function user () {

		$this->database_username = 'user';
		$this->database_password = '******';

		$this->connect();

	}

	// set up a maintance user, priveleges: SELECT, INSERT, UPDATE, DELETE
	// this user is used for cron jobs and other maintance tasks
	// DANGER: should not be used in any end-user part of the app 
	function maintance () {

		$this->database_username = 'maintance';
		$this->database_password = '******';

		$this->connect();

	}

}

?>

 

Whats wrong with this?

 

Daniel

Link to comment
https://forums.phpfreaks.com/topic/94847-php5-class-problems/
Share on other sites

hi,

but the most important thing you are missing here is, Which I got at glance is

whenever you declear the object of any class it should be like this

 

$obj= new ClassName();//Class Name

if you notice your code carefully you are not using parenthesis with your class name when creating object

so

private $database = new database;//wrong approach

try this

private $database = new database();//correct one.

try out this! I am sure the parse error for new line will be eliminated.

Thanks!

Keep Smile

Numan Khan

 

Link to comment
https://forums.phpfreaks.com/topic/94847-php5-class-problems/#findComment-487632
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.