Re: Confusion with objects
| From: | lallous | Date: | Wed, 07 Aug 2002 13:07:20 +0000 |
| Subject: | Re: Confusion with objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111495@lists.php.net to get a copy of this message | ||
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