Class for database-access doesn't work

From: Date: Sun, 11 Nov 2001 00:40:54 +0000
Subject: Class for database-access doesn't work
Groups: php.general 
Request: Send a blank email to php-general+get-74137@lists.php.net to get a copy of this message
Hi, I just tried to write a simple class for opening a MySQL-database with PHP. The database get's opened, but the handle isn't transfered back. I can then use the database, but only if I don't specify the handle in mysql_query. Any ideas? Code: db.php: <? class Database { var $connect; var $database; function Database($host="local") { switch ($host) { case "local" : $this->$connect = mySQL_connect("host","user","pass"); $this->$database = mysql_select_db("db", $this->$connect); break; } } function getConnect() { return $this->$connect; } function getDatabase() { return $this->$database; } } ?> test.php: <html> <head> </head> <body> <? include("lib/db.php"); $db = new Database(); $connect = $db->$getConnect; $result = mysql_query("select * from data"); while ($data = mysql_fetch_array($result)) { extract($data); echo "-".$id."-<br>"; } ?> </body> </html>

« previous php.general (#74137) next »