How can I save a dbhandle in an object?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
zylinder
Forum Newbie
Posts: 9
Joined: Thu Feb 17, 2005 1:27 pm
Location: Austria

How can I save a dbhandle in an object?

Post by zylinder »

Hi everybody!

I want to save a dbhandle in an object. My first thought was:

Code: Select all

$this->dbh = @mysql_connect($host, $user, $pw) or print mysql_error();
But when I want to close the connection the following code produces an error.

Code: Select all

mysql_close($this->dbh)
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource

I don't get it?
var_dump() shows that the var dbh is a resource ???

Thanx for your help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where and when do you call close on it?

For future reference, use

Code: Select all

when you post php code.
Post Reply