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 Quote 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) Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.