$conf = Conf::instance(); } function conn () { $db_conf = $this->$conf->get("db"); $conn = mysql_pconnect($db_conf['host'],$db_conf['dbuser'],$db_conf['passwd']) or die("cannot connect ".mysql_error()); $this->$conf->set("dbh",$conn); } function checkConn () { if(! $this->$conf->get("dbh")) { $this->conn(); } } function ins ($sql) { $this->checkConn(); $db_conf = $this->$conf->get("db"); mysql_select_db($db_conf['dbname'], $this->$conf->get("dbh")); return mysql_query($sql, $this->$conf->get("dbh")) or die("cannot insert |". $sql."| ".mysql_error()); } function sel ($sql) { $db_conf = $this->$conf->get("db"); $this->checkConn(); $array = array(); mysql_select_db($db_conf['dbname'],$this->$conf->get("dbh")) or die("cannot select db ".$db_conf['dbname']." ".mysql_error()); $results = mysql_query($sql, $this->$conf->get("dbh")) or die("bad select $sql " . mysql_error()); while($row = mysql_fetch_assoc($results)) { $array[]=$row; } mysql_free_result($results); $this->disconnect(); return $array; } function del ($sql) { $this->checkConn(); mysql_query($sql, $this->$conf->get("dbh")); } function disconnect () { $conn = $this->$conf->get("dbh"); mysql_close($conn); $this->$conf->set("dbh", 0); } } ?>