Connecting to mySQL with $this->
Hi all - I've been creating procedural code on a WAMP platform for three years. I'm just beginning to learn OOP via PHP5. Here's the problem:
I can connect to mySQL database with the following code:
$connect=mysql_connect('localhost','rick','1 23456');
$hDB=mysql_select_db('profphp5',$connect);
This works each time, every time.
When I try to OOP code this (via Programmer-to-Programmer Professional PHP5) as:
public function __construct($widgetID) {
$this->connect=mysql_connect('localhost','rick','123456' );
$this->hDB=mysql_select_db('profphp5',$this->connect);
if(! is_resource($this->$hDB)) {
throw new Exception('Unable to connect to the database.');
}
}
I throw an Exception each time every time.
Can anyone help me solve this problem? All suggestions are appreciated!
Thanks - Rick
Rick
|