Re: Confusion with objects
| From: | Jason Wong | Date: | Wed, 07 Aug 2002 12:57:42 +0000 |
| Subject: | Re: Confusion with objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111498@lists.php.net to get a copy of this message | ||
On Wednesday 07 August 2002 19:46, Michael Egan wrote:
> 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.
If you're doing this for the fun of it then go ahead. If not, I suggest using
one of the numerous classes out there which does this type of stuff.
> 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.
mysql_connect() uses some builtin default values for $host, $user & $password
if they're not provided.
> 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?
The correct way to do the test is:
if($result === FALSE)
return false;
else
return true;
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
Plumber mistook routing panel for decorative wall fixture
*/