...

View Full Version : pleas help me how to connect db with php class



verak
12-15-2010, 11:11 AM
here is my class establish a connection to database...

// connect to database
class DBselect{
$host = 'localhost';
$user = '';
$pass = 'root';
$database = 'safarish';
function connectdb(){
$link = mysql_connect($host,$user,$pass);
$DBok = mysql_select_db($database,$link) or die('Connect is not established!');
return $DBok;
}

}

and here is my index.php code for access class instance... in action.php i define the DBselect class


include('classes/actions.php');
$DB = new DBselect();
$DB->connectdb();

but i have following error ...
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in D:\xampp\htdocs\web1\classes\actions.php on line 4

abduraooft
12-15-2010, 11:38 AM
and here is my index.php code for access class instance... in action.php i define the DBselect class

include('classes/actions.php');
$DB = new DBselect();
$DB->connectdb();

but i have following error ...
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in D:\xampp\htdocs\web1\classes\actions.php on line 4 Is that your full code? Are you including actions.php in that file itself?

poyzn
12-15-2010, 11:53 AM
check for ";" in actions.php after third line



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum