
- You are not logged in. | Login
November 16, 2006 8:28 pm
- cplusplus
- Member


php noobie, looking for help with classes
Hi all, I'm a n00b when it comes to PHP, but I come from a background of C++ programming.
My boss recently started a project to revamp our website to include some database driven pages with PHP, and I was put in charge of creating the scripts to communicate with the database.
Being a stickler for structured code, I decided the best route would be to create a class in PHP for database communications, but I'm having some trouble with syntax. Here's a test class I tried to create, and I'm getting parser errors when I try to include it in my test page:
class DB_class {
var $host = "host";
var $user = "user";
var $pass = "pass";
function DB_class { #constructor
$db = mysql_connect($this->host, $this->user, $this->pass);
return $db;
};
};In my test.php i'm using
include("db_class.php");
$db_link = new DB_class;And, getting 'expecting FUNCTION' error messages. The syntax seems right as far as I can tell from the manual, so I'm sort of stumped on this silly problem. Any help would be greatly appreciated.
November 17, 2006 6:34 pm
- IBdaMac
- Member


Re: php noobie, looking for help with classes
try dropping the semicolon at the end of the function
function DB_class { #constructor
$db = mysql_connect($this->host, $this->user, $this->pass);
return $db;
}; <--- right here


