marcus.whybrow Posted June 14, 2007 Share Posted June 14, 2007 Hi, I have constructed this class for handeling making connections to a mysql database, but I can understand why this will not work, it allways returns the error: Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in C:\Inetpub\wwwroot\scriptsoft.co.uk\cpt\index.php on line 18 and this is the code: <?php class Connection { var $result; function Connection($localhost, $username, $password, $database){ $con = mysql_connect($localhost,$username,$password); mysql_select_db($database, $con); if($con) { $this->result = 'successful connection'; } else { $this->result = 'failed connection'; } } $test = &new Connection('localhost','***username(removed)***','***password(removed)***','cpt'); //line 18 echo $test->result; ?> Any help would be greatly apprieciated. Thanks, Marcus Link to comment https://forums.phpfreaks.com/topic/55652-class-is-not-working-correctly/ Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 <?php class Connection { var $result; function Connection($localhost, $username, $password, $database){ $con = mysql_connect($localhost,$username,$password); mysql_select_db($database, $con); if($con) { $this->result = 'successful connection'; } else { $this->result = 'failed connection'; } } } // Add curly bracket here $test = &new Connection('localhost','***username(removed)***','***password(removed)***','cpt'); //line 18 echo $test->result; ?> You never close your brackets for your Connection class (see code for added curly bracket) Link to comment https://forums.phpfreaks.com/topic/55652-class-is-not-working-correctly/#findComment-275013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.