DB usage inside a class
| From: | Burak DAYIOGLU | Date: | Mon, 12 Mar 2001 10:22:30 +0000 |
| Subject: | DB usage inside a class | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-4@lists.php.net to get a copy of this message | ||
Hello All,
I'm trying to pass a database instance to a class instance to no avail.
The below code doesn't work and handle is a db_error instance.
DNS_DATABASE equals to pgsql...
cheers,
-bd
<?php
require_once("DB.php");
require_once("/code/config.php");
class sample {
function sample(&$database) {
$this->dbHandle=$database;
}
function execute() {
$query="insert into host values (9,'test','test')";
$handle=$this->dbHandle->simplequery($query);
var_dump($handle);
}
}
$dsn=array(phptype=>DNS_DATABASE,hostspec=>"localhost",database=>"dns");
$database=DB::connect($dsn);
$x=new sample(&$database);
$x->execute();
?>