0

Hi,
I am having problem with my code can anybody help it is giving me this error
Parse error: parse error, expecting `T_FUNCTION'on line 4.
Here is my code

<?php class database
{
$dbconnect=NULL;
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname="db_student_info";
function db_connect()
{

global $dbhost,$dbuser,$dbpass,$dbname;
if(!$dbconnect)
$dbconnect=mysql_connect($dbhost,$dbname,$dbpass);
if(!$dbconnect)
{return 0;}
else if(!mysql_select_db($dbname))
{
return 0;
}
else{
return $dbconnect;
}
}
}?>
thanx in advance

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by saadi06
0

Here's the correct code:

<?php class database
{
var $dbconnect=NULL;
var $dbhost="localhost";
var $dbuser="root";
var $dbpass="";
var $dbname="db_student_info";
function db_connect()
{

global $dbhost,$dbuser,$dbpass,$dbname;
if(!$dbconnect)
$dbconnect=mysql_connect($dbhost,$dbname,$dbpass);
if(!$dbconnect)
{return 0;}
else if(!mysql_select_db($dbname))
{
return 0;
}
else{
return $dbconnect;
}
}
}?>

Variables are defined by var and functions by function.

0

More specifically: Class variables (properties) need to be declared with public, private or protected. Declaration with var (public) is supported for compatibility reasons. You can read more here.

Edited by pritaeas: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.