Confusion with objects
| From: | Michael Egan | Date: | Wed, 07 Aug 2002 11:46:21 +0000 |
| Subject: | Confusion with objects | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111494@lists.php.net to get a copy of this message | ||
Help!
I've finally decided to try and implement some limited objects with a new project - beginning
with a connection to the database itself. However, it's not working as I would have expected.
Usually I would connect to the database with a function such as:
function db_connect()
{
$result = @mysql_connect($host, $user, $password');
if(!$result)
return false;
else
return true;
}
Provided the correct parameters were passed to the function the connection would be established and
the function would return a positive value. I would have thought the same logic would apply if
housing the function within a class such as:
class Db
{
function DbConnect()
{
$result = @mysql_connect($host, $user, $password');
if(!$result)
return false;
else
return true;
}
}
Yet, when trying to test this the latter function seems to return a positive value irrespective of
the information contained in variables such as $host and $user.
This might seem a minor issue but it's driving me nuts. I know the above object is not written
in the most elegant manner but I'm trying to understand the basics of this. I'm sure
I'm missing something idiotically simple but what is it?
Thanks in advance,
Michael Egan