Date: 03/11/05 (PHP Community) Keywords: php, mysql, database, sql I have a base class in which I'd like to extend. The thing is, the base class connects to a database. How can I make it so any classes I extend from base class will share the one connection to the database and not make a duplicate connection for each object i make? class base { var $connection; function base(){ $this->connection = mysql_connection("server","user","password"); mysql_select_db("database",$this->connection); } function exec($query){ return mysql_query($query,$this->connection); } } class child extends base { var $foo; var $bar; function child(){ $this->foo = mysql_result($this->exec("select foo from foobar"),0); } } I'd like it so no matter how many objects i make of the child class, they all share the same database connection. I think in PHP5 you can do something like "shared $connection" but i'm using php4. tia -ryan Source: http://www.livejournal.com/community/php/271677.html
|