RE: [PHP] Re: Confusion with objects

From: Date: Wed, 07 Aug 2002 12:25:21 +0000
Subject: RE: [PHP] Re: Confusion with objects
Groups: php.general 
Request: Send a blank email to php-general+get-111496@lists.php.net to get a copy of this message
Thanks for the quick response. If no information is passed to the variables - as would be the case with the sample I posted - I still seem to be getting a positive value returned as though a connection was being made to the database. It's this that I don't understand. The only way in which the function seems to fail to connect to the database is if I put in incorrect values as opposed to no values at all. Michael -----Original Message----- From: lallous [mailto:phplist@lgwm.org] Sent: 07 August 2002 06:07 To: php-general@lists.php.net Subject: [PHP] Re: Confusion with objects function db_connect() { $result = @mysql_connect($host, $user, $password'); if(!$result) return false; else return true; } hmm, how are you passing the $host, $user, $password? I can't see them getting passed! you can redefine the function as: function db_connect($host, $user, $password) and in case you want to access class memeber variables from within this function to this: mysql_connect($this->host, $this->user, $this->password) . . Elias "Michael Egan" <MEgan@3tc.org.uk> wrote in message news:9926D602EE82FB4FB203E442253043C402FD5C@snip-exch.snipdom.co.uk... 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#111496) next »