
October 6th, 2003, 05:32 PM
|
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 5
|
|
|
Problems with PHP OOP
Ok, i am attempting to write a class to deal with mysql database actions, however i am having difficaulty with some of the classes local variables - they appear to be converted to resources
PHP Code:
example code:
class myclass
{
var $host;
var $user;
var $password;
var $db_name;
var $connect_id;
// Constructor
function myclass( $host, $username, $password )
{
$this->$host = $host;
$this->$user = $username;
$this->$password = $password;
$this->$db_name='';
$this->$connect_id='';
if ( $this->$connect_id = mysql_connect( $host, $username, $password ) )
{
return TRUE;
}
else
{
return FALSE;
}
}
Before the if statement, ie before mysql_connect is called, the local variables are as you would expect, host, user, password all equal the parameter passed, db_name and connect_id are blank, and after mysql_connect they are all 'Resource id #1'.
As far as i can see the classes local vars should not be affected at all, save $connection_id. This is annoying as other functions may need to access these variables later.
Does anyone know why this happens, or how to stop it. (or indeed, how to access the values instead of 'resource id #1')
Cheers
Last edited by mattp23 : October 6th, 2003 at 05:42 PM.
|